Skip to main content

Unified Vector DB abstraction layer for Python — clean adapters for FAISS, ChromaDB, Qdrant and more

Project description

dd-vectordb

Unified Vector DB abstraction layer for Python.

Add semantic search to any project in minutes. Swap backends (in-memory, FAISS, ChromaDB, Qdrant) without changing your application code.

Supported Backends

Adapter Class Extra Notes
In-memory (NumPy) InMemoryVectorDB (none) Brute-force cosine; dev/testing
FAISS FAISSVectorDB faiss Facebook AI; exact + ANN
ChromaDB ChromaVectorDB chroma Embedded HNSW; persistent
Qdrant QdrantVectorDB qdrant Production-grade; local/remote

Install

pip install dd-vectordb                  # InMemoryVectorDB only (numpy)
pip install "dd-vectordb[faiss]"         # + FAISS
pip install "dd-vectordb[chroma]"        # + ChromaDB
pip install "dd-vectordb[qdrant]"        # + Qdrant
pip install "dd-vectordb[all]"           # all adapters
pip install "dd-vectordb[dev]"           # dev tools

Quick Start

import numpy as np
from dd_vectordb import InMemoryVectorDB

# 1. Embed your texts (any encoder — OpenAI, sentence-transformers, Ollama, etc.)
texts = ["The quick brown fox", "Python programming", "Vector search rocks"]
embeddings = [np.random.rand(768).tolist() for _ in texts]  # replace with real embeddings

# 2. Add to the store
db = InMemoryVectorDB()
db.add_texts(texts=texts, embeddings=embeddings)

# 3. Search
query_vec = np.random.rand(768).tolist()  # replace with real query embedding
results = db.search(query_vec, k=2)
for r in results:
    print(f"#{r.rank}  score={r.score:.4f}  {r.document.text}")

API Reference

Core methods (all adapters)

Method Returns Description
add_documents(docs) None Add/upsert Document objects
add_texts(texts, embeddings, ids?, metadatas?) list[str] Convenience: build Documents and add
search(query_vector, k=5, filter?) list[SearchResult] Top-k similarity search
delete(ids) int Delete by ID; returns count removed
clear() None Remove all documents
count() int Number of documents stored
get_by_ids(ids) `list[Document None]`
collection_info() CollectionInfo Name, count, dimension, metric
close() None Release resources

Context manager

with FAISSVectorDB(dimension=768) as db:
    db.add_texts(texts, embeddings)
    results = db.search(query, k=5)
# close() called automatically

Pydantic models

from dd_vectordb import Document, SearchResult, CollectionInfo

doc = Document(id="1", text="hello", embedding=[0.1, 0.9], metadata={"src": "wiki"})
result: SearchResult  # .document, .score, .rank
info: CollectionInfo  # .name, .adapter, .count, .dimension, .metric

Examples

With FAISS

from dd_vectordb import FAISSVectorDB

db = FAISSVectorDB(dimension=768, metric="cosine")
db.add_texts(texts=["hello world"], embeddings=[[...768 floats...]])
results = db.search([...768 floats...], k=5)

# Persist to disk
db.save("my_index.faiss")
db2 = FAISSVectorDB.load("my_index.faiss")

With ChromaDB (persistent)

from dd_vectordb import ChromaVectorDB

db = ChromaVectorDB(collection_name="my_docs", persist_directory="./chroma_data")
db.add_texts(texts=["hello"], embeddings=[[0.1, 0.9]])
results = db.search([0.1, 0.9], k=1)

With Qdrant (in-memory)

from dd_vectordb import QdrantVectorDB

db = QdrantVectorDB(dimension=768, collection_name="docs")
db.add_texts(texts=["hello"], embeddings=[[...768 floats...]])
results = db.search([...768 floats...], k=5)

Metadata filtering

db.add_texts(
    texts=["wiki article", "blog post"],
    embeddings=[emb1, emb2],
    metadatas=[{"source": "wiki"}, {"source": "blog"}],
)
# Only search within wiki documents
results = db.search(query_vec, k=5, filter={"source": "wiki"})

Cookbooks

See cookbook/ for runnable examples:

  • 01_in_memory_basics.py — full walkthrough with zero extra deps
  • 02_faiss_basics.py — FAISS with save/load, metadata filtering

Running Tests

pip install -e ".[dev]"
python -m pytest

Tests use InMemoryVectorDB — no external server or extra install required.

Design

See docs/DESIGN.md for:

  • Why pre-computed embeddings?
  • Adapter comparison table
  • Score normalisation convention
  • How to add a new adapter

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dd_vectordb-0.1.0.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dd_vectordb-0.1.0-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file dd_vectordb-0.1.0.tar.gz.

File metadata

  • Download URL: dd_vectordb-0.1.0.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for dd_vectordb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 726297b2ed2e9bfe62c9362e885bf0ffb44c02c12cc60c524d4007f00f17cfdf
MD5 b7bf5db861aab4e1e9d7925077a0d69e
BLAKE2b-256 5d89fe88ff8fb459798a36df6232d3844f506c87daf8a71f641dedfc775f345b

See more details on using hashes here.

File details

Details for the file dd_vectordb-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dd_vectordb-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.5

File hashes

Hashes for dd_vectordb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70880a761f4849831dbff544616dca9342973a571d521ddedb09263e06181854
MD5 6cec74580b572f2448f7290b6693556f
BLAKE2b-256 1d4880d5313f0a7f73e960ec647efb33eea90bb2ee9667fe4ce60d13fb96cab7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page