Reference
srvdb.integrations.langchain.SrvDBVectorStore
LangChain VectorStore over a SrvDB database.
LangChain VectorStore over a SrvDB database.
class srvdb.integrations.langchain.SrvDBVectorStore(database, embedding: Embeddings)Parameters
Section titled “Parameters”-
database : database object An open database whose dimension matches the embedding model.
-
embedding : langchain_core.embeddings.Embeddings Model used for texts and queries.
Raises
Section titled “Raises”-
ImportError On import, when
langchain-coreis not installed; install withpip install "srvdb[langchain]". -
ValueError From
add_texts: lengths differ or an embedding has the wrong dimension. From searches:kbelow 1, afilterthat is neither a dict nor a callable, or a dict filter with an unknown operator or wrong operand type. Fromdelete:idsis None. Fromfrom_texts:pathmissing ortextsempty. -
OSError, RuntimeError Passed through from the underlying database.
- Methods:
add_texts(texts, metadatas=None, *, ids=None),add_documents(documents),delete(ids),get_by_ids(ids),similarity_search(query, k=4, filter=None),similarity_search_with_score(...),similarity_search_by_vector(...),similarity_search_with_score_by_vector(...), and the classmethodfrom_texts(texts, embedding, metadatas=None, *, ids=None, path, index="hnsw", **options)(opens an existing database with the same settings, seesrvdb.createwithexist_ok=True). Properties:embeddings,database. - Existing ids are replaced (writes use
upsert). Withoutids, random UUIDs are assigned. filteris a dict or a callable taking the metadata dict. A dict runs inside SrvDB (see Filtered search):{"kind": "fruit"}for equality, or operators such as{"price": {"$lt": 5}}and$and/$or/$not, and returnskdocuments wheneverkmatch. A callable, or a dict with a dotted key such as"a.b"(equality on that literal key only), runs on search results, over-fetching untilkmatches are found.- Scores are cosine similarities; LangChain relevance scores map them to
(score + 1) / 2. - Durability: every write method calls
save()before it returns, so added and deleted documents survive a crash. - Thread safety: as thread-safe as the underlying database. The adapter makes no network calls.
Examples
Section titled “Examples”import srvdbfrom langchain_core.embeddings import DeterministicFakeEmbeddingfrom srvdb.integrations.langchain import SrvDBVectorStore
store = SrvDBVectorStore(srvdb.create("./vectors", dimension=128), DeterministicFakeEmbedding(size=128))store.add_texts(["red apple", "blue sky"], [{"kind": "fruit"}, {"kind": "weather"}])docs = store.similarity_search("red apple", k=1, filter={"kind": "fruit"})print(docs[0].page_content)# red appleSee also
Section titled “See also”srvdb.integrations.llamaindex.SrvDBVectorStore: LlamaIndex vector store over a SrvDB database.srvdb.open: Open an existing database by path.
Was this page helpful? Tell us in Discussions.