skills/cocoindex/references/setup_database.md
Setup instructions for databases used with CocoIndex.
cat > docker-compose.yml <<EOF
version: '3.8'
services:
postgres:
image: pgvector/pgvector:pg16
container_name: cocoindex-postgres
environment:
POSTGRES_USER: cocoindex
POSTGRES_PASSWORD: cocoindex
POSTGRES_DB: cocoindex
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U cocoindex"]
interval: 5s
timeout: 5s
retries: 5
volumes:
postgres_data:
EOF
docker-compose up -d
Connection URL: postgres://cocoindex:cocoindex@localhost:5432/cocoindex
psql "postgres://user:password@localhost/dbname" \
-c "CREATE EXTENSION IF NOT EXISTS vector;"
# .env
POSTGRES_URL=postgres://cocoindex:cocoindex@localhost:5432/cocoindex
pip install sqlite-vec
Note for macOS: Use Homebrew Python for extension support:
brew install python
from cocoindex.connectors import sqlite
conn = sqlite.connect("./data.db", load_vec="auto") # Auto-load sqlite-vec
conn = sqlite.connect("./data.db", load_vec=True) # Require sqlite-vec
conn = sqlite.connect("./data.db", load_vec=False) # No vector support
pip install lancedb
No setup needed. Just specify a directory:
conn = await lancedb.connect_async("./lancedb_data")
# AWS S3
conn = await lancedb.connect_async("s3://your-bucket/lancedb_data")
# Google Cloud Storage
conn = await lancedb.connect_async("gs://your-bucket/lancedb_data")
Configure credentials via environment variables (AWS_ACCESS_KEY_ID, GOOGLE_APPLICATION_CREDENTIALS, etc.).
cat > docker-compose.yml <<EOF
version: '3.8'
services:
qdrant:
image: qdrant/qdrant:latest
container_name: cocoindex-qdrant
ports:
- "6333:6333"
- "6334:6334"
volumes:
- qdrant_data:/qdrant/storage
volumes:
qdrant_data:
EOF
docker-compose up -d
client = qdrant.create_client(
url="https://your-cluster.qdrant.io",
api_key="your-api-key",
prefer_grpc=True,
)
# .env
QDRANT_URL=http://localhost:6333
# QDRANT_API_KEY=your-key # For Qdrant Cloud
docker run --rm -p 8000:8000 surrealdb/surrealdb:latest \
start --user root --pass root
factory = surrealdb.ConnectionFactory(
url="ws://localhost:8000/rpc",
namespace="my_ns",
database="my_db",
credentials={"username": "root", "password": "root"},
)
# docker-compose.yml
version: '3.8'
services:
postgres:
image: pgvector/pgvector:pg16
environment:
POSTGRES_USER: cocoindex
POSTGRES_PASSWORD: cocoindex
POSTGRES_DB: cocoindex
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
qdrant:
image: qdrant/qdrant:latest
ports:
- "6333:6333"
- "6334:6334"
volumes:
- qdrant_data:/qdrant/storage
volumes:
postgres_data:
qdrant_data:
# .env
POSTGRES_URL=postgres://cocoindex:cocoindex@localhost:5432/cocoindex
QDRANT_URL=http://localhost:6333
docker-compose ps # Check if running
nc -zv localhost 5432 # Check port
psql -U postgres -c "SELECT * FROM pg_available_extensions WHERE name = 'vector';"
Use the pgvector/pgvector:pg16 Docker image which includes it.
import sqlite3
conn = sqlite3.connect(":memory:")
conn.enable_load_extension(True) # Should not raise
If it fails, use Homebrew Python on macOS or ensure Python was built with --enable-loadable-sqlite-extensions on Linux.
curl http://localhost:6333/ # Check health
docker logs cocoindex-qdrant # Check logs