Skip to main content

LangChain Integration

langchain-zerodb is a real, published PyPI package (v0.1.0) that plugs ZeroDB into LangChain as a VectorStore. Every sample on this page was installed and run live against the real API.

Install

pip install langchain-zerodb

Quickstart — verified live

Run against a real instant-db project created via npx zerodb-cli init.

from langchain_zerodb import ZeroDBVectorStore

vectorstore = ZeroDBVectorStore(
    api_key="your-api-key",
    project_id="your-project-id",
)

# Add documents (free BAAI/bge-m3 embeddings, generated server-side)
ids = vectorstore.add_texts(
    ["ZeroDB is fast", "Semantic search is powerful"],
    metadatas=[{"source": "docs"}, {"source": "blog"}],
)

# Similarity search
results = vectorstore.similarity_search("fast database", k=5)
for doc in results:
    print(doc.page_content, doc.metadata)

# Similarity search with score
scored = vectorstore.similarity_search_with_score("fast database", k=5)
for doc, score in scored:
    print(f"{score:.3f}: {doc.page_content}")

Real output from running the above:

ZeroDB is fast {'model': 'bge-m3', 'source': 'docs', 'dimensions': 1024, ...}
Semantic search is powerful {'model': 'bge-m3', 'source': 'blog', 'dimensions': 1024, ...}
0.719: ZeroDB is fast
0.550: Semantic search is powerful

Known quirk found during live testing

add_texts() returns an empty list instead of the real vector IDs — the package reads a vector_ids key from the embed-and-store response that the current API response does not contain. The texts ARE stored correctly (confirmed by the successful searches above retrieving them) — only the returned ID list is wrong. Don't rely on the return value of add_texts(); re-query if you need the IDs.

Use in a RAG chain

from langchain_zerodb import ZeroDBVectorStore
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough

vectorstore = ZeroDBVectorStore(api_key="your-api-key", project_id="your-project-id")
retriever = vectorstore.as_retriever(search_kwargs={"k": 5})

template = "Answer based on context:\n{context}\n\nQuestion: {question}"
prompt = ChatPromptTemplate.from_template(template)

chain = (
    {"context": retriever, "question": RunnablePassthrough()}
    | prompt
)

Reference

ZeroDB — part of AINative Studio