InMemoryVectorDB
Stores everything in memory. Great for development, testing, and small datasets.Name for this collection of documents.
Vector dimensions. Must match your embedder output.
- No external dependencies
- Uses cosine similarity for search
- Supports metadata filtering
- Data is lost when the process exits
PgVectorDB
Uses PostgreSQL with thepgvector extension. Suitable for production workloads with persistent storage and scalable search.
PostgreSQL connection string. Defaults to the
DATABASE_URL environment variable.Database table name for storing documents and embeddings.
Vector dimensions. Must match your embedder.
Requires Your PostgreSQL instance must have the
psycopg[binary] and pgvector. Install with:pgvector extension enabled:- Persistent storage across restarts
- Uses IVFFlat index for fast approximate nearest neighbor search
- Supports metadata filtering
- Scales to millions of documents
Using with Knowledge
VectorDB Interface
Both implementations share the same interface:| Method | Description |
|---|---|
add(documents) -> List[str] | Add documents, returns their IDs |
aadd(documents) -> List[str] | Async add |
search(query_embedding, top_k, filter) | Search by vector similarity |
asearch(query_embedding, top_k, filter) | Async search |
delete(ids) | Delete documents by ID |
clear() | Remove all documents |
count() -> int | Number of stored documents |
Metadata Filtering
Filter search results by document metadata:Creating a Custom VectorDB
SubclassVectorDB to integrate your preferred vector store:
Choosing a Vector Database
| InMemoryVectorDB | PgVectorDB | |
|---|---|---|
| Setup | None | Requires PostgreSQL |
| Persistence | No | Yes |
| Scale | Thousands of docs | Millions of docs |
| Best for | Development, testing, demos | Production |