Skip to main content

LangChain Integration

vectlite.langchain.VectLiteVectorStore implements the LangChain VectorStore protocol. Drop it into any LangChain pipeline that takes a vector store — RAG, RetrievalQA, agent memory, etc.

pip install vectlite langchain-core

langchain-core is an optional dependency of vectlite — installing it unlocks the integration.

Quick start

from vectlite.langchain import VectLiteVectorStore
from langchain_openai import OpenAIEmbeddings

store = VectLiteVectorStore(
path="my.vdb",
embedding=OpenAIEmbeddings(),
dimension=1536,
)

store.add_texts(
["Auth setup guide for SSO", "Billing FAQ"],
metadatas=[{"source": "docs"}, {"source": "faq"}],
)

results = store.similarity_search("how to authenticate", k=3)
for doc in results:
print(doc.page_content, doc.metadata)

Supported methods

MethodDescription
add_texts(texts, metadatas=None, ids=None)Embed and insert texts.
add_documents(docs)Insert LangChain Document objects.
similarity_search(query, k=4)Top-k semantic search.
similarity_search_with_score(query, k=4)Same, returns (doc, score) tuples.
similarity_search_by_vector(embedding, k=4)Search with a pre-computed embedding.
delete(ids)Remove records by id.
VectLiteVectorStore.from_texts(texts, embedding, ...)Class-method constructor — creates a database, ingests, returns the store.

RetrievalQA example

from langchain.chains import RetrievalQA
from langchain_openai import ChatOpenAI

retriever = store.as_retriever(search_kwargs={"k": 5})
qa = RetrievalQA.from_chain_type(
llm=ChatOpenAI(model="gpt-4o-mini"),
chain_type="stuff",
retriever=retriever,
)

answer = qa.invoke("How do I configure SSO?")

Filtering

Pass a filter kwarg through search_kwargs to scope retrieval:

retriever = store.as_retriever(
search_kwargs={"k": 5, "filter": {"source": "docs"}}
)

The filter is forwarded to vectlite's metadata filter engine — full MongoDB-style operators are available.

When to pick vectlite over other LangChain stores

  • Local-first / no server — vectlite is a single .vdb file, no Docker, no network. Beats Chroma / Qdrant when you ship a desktop app or run offline.
  • Hybrid search out of the box — sparse + dense fusion is built in. Most LangChain stores need a separate BM25 retriever.
  • Crash-safe WAL + transactions — atomic batch writes without bolt-on commit semantics.

Combining with vectlite-native features

The underlying database is accessible — use it directly for features the LangChain protocol doesn't expose (TTL, payload indexes, quantization, multi-vector search):

store.db.create_index("source", "keyword")
store.db.enable_quantization("scalar")