Skip to main content
Zvec is an open-source, in-process vector database — lightweight, lightning-fast, and designed to embed directly into applications. Built on Proxima (Alibaba’s battle-tested vector search engine), it delivers production-grade, low-latency, scalable similarity search with minimal setup
This notebook demonstrates how to use the ‘Zvec’ vector database in LangChain.

Installation

pip install -qU  langchain-community zvec dashscope
We want to use DashScopeEmbeddings so we also have to get the Dashscope API Key.
import getpass
import os

if "DASHSCOPE_API_KEY" not in os.environ:
    os.environ["DASHSCOPE_API_KEY"] = getpass.getpass("DashScope API Key:")

Example

from langchain_community.embeddings.dashscope import DashScopeEmbeddings
from langchain_community.vectorstores import Zvec
from langchain_text_splitters import CharacterTextSplitter
from langchain_community.document_loaders import TextLoader

loader = TextLoader("../../how_to/state_of_the_union.txt")
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
docs = text_splitter.split_documents(documents)

embeddings = DashScopeEmbeddings()
We can create Zvec from documents.
zvec = Zvec.from_documents(docs, embeddings)

query = "What did the president say about Ketanji Brown Jackson"
docs = zvec.similarity_search(query)
print(docs)
We can add texts with meta datas and ids, and search with meta filter.
texts = ["foo", "bar", "baz"]
metadatas = [{"source": "test_data"} for _ in texts]
ids = ["0", "1", "2"]

zvec.add_texts(texts, metadatas=metadatas, ids=ids)

docs = zvec.similarity_search("foo")
print(docs)
[Document(metadata={'source': 'test_data'}, page_content='foo')]

Connect these docs to Claude, VSCode, and more via MCP for real-time answers.