LangChain VectorStore integration for VectorDB
Project description
vectordb-langchain
LangChain VectorStore integration for VectorDB.
Installation
pip install vectordb-langchain
Quick start
from vectordb_langchain import VectorDBVectorStore
store = VectorDBVectorStore(
api_key="sk_live_your_key",
base_url="http://localhost:8888",
collection="my_docs",
embedding_model="text-embedding-3-small",
)
# Insert texts with metadata
ids = store.add_texts(
texts=["LangChain is great", "VectorDB is fast"],
metadatas=[{"source": "docs"}, {"source": "docs"}],
)
# Search
docs = store.similarity_search("What is LangChain?", k=2)
Constructor parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key |
str |
required | Bearer token (sk_live_...) |
base_url |
str |
required | VectorDB API URL |
collection |
str |
"default" |
Collection name |
embedding_model |
str | None |
None |
Server-side model name |
embeddings |
Embeddings | None |
None |
LangChain client-side embeddings |
k |
int |
4 |
Default result count |
timeout |
float |
30.0 |
HTTP timeout (seconds) |
Embedding modes
Server-side (default)
Pass embedding_model — raw text is sent to VectorDB, which embeds it internally.
store = VectorDBVectorStore(
api_key="sk_live_...",
base_url="http://localhost:8888",
embedding_model="text-embedding-3-small",
)
Client-side
Pass a LangChain Embeddings object — vectors are computed locally and raw floats are sent to VectorDB.
from langchain_openai import OpenAIEmbeddings
store = VectorDBVectorStore(
api_key="sk_live_...",
base_url="http://localhost:8888",
embeddings=OpenAIEmbeddings(),
)
Methods
add_texts
ids: List[str] = store.add_texts(
texts=["doc1", "doc2"],
metadatas=[{"source": "a"}, {"source": "b"}],
)
similarity_search
docs: List[Document] = store.similarity_search(
query="your question",
k=4,
filter={"source": "wiki"}, # optional metadata filter
)
similarity_search_with_score
results: List[Tuple[Document, float]] = store.similarity_search_with_score(
query="your question",
k=4,
)
for doc, score in results:
print(score, doc.page_content)
similarity_search_by_vector
docs = store.similarity_search_by_vector(
embedding=[0.1, 0.2, ...],
k=4,
)
from_texts (class method)
store = VectorDBVectorStore.from_texts(
texts=["doc1", "doc2"],
api_key="sk_live_...",
base_url="http://localhost:8888",
embedding_model="text-embedding-3-small",
)
Using as a LangChain retriever
retriever = store.as_retriever(search_kwargs={"k": 4})
# Inside a RAG chain
from langchain.chains import RetrievalQA
from langchain_openai import ChatOpenAI
qa = RetrievalQA.from_chain_type(llm=ChatOpenAI(), retriever=retriever)
answer = qa.invoke({"query": "What is VectorDB?"})
Error handling
from vectordb_langchain import VectorDBError
try:
store.add_texts(["hello"])
except VectorDBError as e:
print(e.status_code, e.detail) # e.g. 401, "Invalid or missing API key."
Running tests
pip install "vectordb-langchain[dev]"
pytest tests/ -v --cov=vectordb_langchain
Publishing to PyPI
pip install hatch
hatch build
hatch publish
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
vectordb_langchain-0.1.0.tar.gz
(57.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vectordb_langchain-0.1.0.tar.gz.
File metadata
- Download URL: vectordb_langchain-0.1.0.tar.gz
- Upload date:
- Size: 57.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74b0dc5b018dc4fe566195b8ca4422614f53d213edb3c6ee63785bb1fa6aa2c2
|
|
| MD5 |
b831925214688a48d0d5fdc5e24d29e1
|
|
| BLAKE2b-256 |
868b729159621ea249d1d698ff95d698a5b3ceb31c174d79a740e44f3dc3b50a
|
File details
Details for the file vectordb_langchain-0.1.0-py3-none-any.whl.
File metadata
- Download URL: vectordb_langchain-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61ca740d743cc936ea7c2bbe1e6ec3c49f71a469cb4a6b24526a5ff9571bfde1
|
|
| MD5 |
d4bb245c97b64c8955afaf05e3954d21
|
|
| BLAKE2b-256 |
8fb6f8bf545e5faeacabff07fbfbc0fcba5f6ecc49c9d63ea2639eaa8687f41d
|