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.1.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.1-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dd_vectordb-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 6bc1fadda6a6236e7925d79f3dae0603d0640bd874b3a1405c6d1e60347d20f3
MD5 54c7adf09042108d8ab6ac9f2f1849a4
BLAKE2b-256 5722ee57aedc77041659c1193ca7e5fcf7a8c1ec38bd0c9eea089350fe70a4c5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dd_vectordb-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3c802321707694744f96fca77d71231aec7b05480c136733e8dfdc2ea81b4187
MD5 5bab691128c49152ede81555a1dd1596
BLAKE2b-256 8b717cf8f33b07cc277ef60f530c9738dd8bc3f0c8efe74a152bb94e143d978e

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