Documentation Index Fetch the complete documentation index at: https://nvd-54.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
ZeusDB is a vector database written in Rust. It supports product quantization, persistent storage, and logging for operational use.
The following sections show how to use ZeusDB with LangChain.
Install the ZeusDB LangChain integration package from PyPI:
pip install - qU langchain - zeusdb
Setup in Jupyter Notebooks
pip install - qU langchain - zeusdb
快速开始
This example uses OpenAIEmbeddings, which requires an OpenAI API key: Get your OpenAI API key here
If you prefer, you can also use this package with any other embedding provider (Hugging Face, Cohere, custom functions, etc.).
Install the LangChain OpenAI integration package from PyPI:
pip install - qU langchain - openai
# Use this command if inside Jupyter Notebooks
#pip install -qU langchain-openai
Please choose an option below for your OpenAI key integration
Option 1: 🔑 Enter your API key each time
Use getpass in Jupyter to securely input your key for the current session:
import os
import getpass
os . environ [ " OPENAI_API_KEY " ] = getpass . getpass ( "OpenAI API Key:" )
Option 2: 🗂️ Use a .env file
Keep your key in a local .env file and load it automatically with python-dotenv
from dotenv import load_dotenv
load_dotenv () # reads .env and sets OPENAI_API_KEY
🎉 Nicely done! You are good to go.
初始化
# Import required Packages and Classes
from langchain_zeusdb import ZeusDBVectorStore
from langchain_openai import OpenAIEmbeddings
from zeusdb import VectorDatabase
# Initialize embeddings
embeddings = OpenAIEmbeddings ( model = "text-embedding-3-small" )
# Create ZeusDB index
vdb = VectorDatabase ()
index = vdb . create ( index_type = "hnsw" , dim = 1536 , space = "cosine" )
# Create vector store
vector_store = ZeusDBVectorStore ( zeusdb_index = index , embedding = embeddings )
管理向量存储
2.1 add items to vector store
from langchain_core . documents import Document
document_1 = Document (
page_content = "ZeusDB is a high-performance vector database" ,
metadata = { "source" : "https://docs.zeusdb.com" },
)
document_2 = Document (
page_content = "Product Quantization reduces memory usage significantly" ,
metadata = { "source" : "https://docs.zeusdb.com" },
)
document_3 = Document (
page_content = "ZeusDB integrates seamlessly with LangChain" ,
metadata = { "source" : "https://docs.zeusdb.com" },
)
documents = [ document_1 , document_2 , document_3 ]
vector_store . add_documents ( documents = documents , ids = [ "1" , "2" , "3" ])
2.2 update items in vector store
updated_document = Document (
page_content = "ZeusDB now supports advanced Product Quantization with 4x-256x compression" ,
metadata = { "source" : "https://docs.zeusdb.com" , "updated" : True },
)
vector_store . add_documents ([ updated_document ], ids = [ "1" ])
2.3 delete items from vector store
vector_store . delete ( ids = [ "3" ])
查询向量存储
3.1 query directly
Performing a simple similarity search:
results = vector_store . similarity_search ( query = "high performance database" , k = 2 )
for doc in results :
print ( f "* { doc . page_content } [ { doc . metadata } ]" )
If you want to execute a similarity search and receive the corresponding scores:
results = vector_store . similarity_search_with_score ( query = "memory optimization" , k = 2 )
for doc , score in results :
print ( f "* [SIM= { score :.3f } ] { doc . page_content } [ { doc . metadata } ]" )
3.2 query by turning into retriever
You can also transform the vector store into a retriever for easier usage in your chains:
retriever = vector_store . as_retriever ( search_type = "mmr" , search_kwargs = { "k" : 2 })
retriever . invoke ( "vector database features" )
ZeusDB-Specific features
4.1 Memory-Efficient setup with product quantization
For large datasets, use Product Quantization to reduce memory usage:
# Create memory-optimized vector store
quantization_config = { "type" : "pq" , "subvectors" : 8 , "bits" : 8 , "training_size" : 10000 }
vdb_quantized = VectorDatabase ()
quantized_index = vdb_quantized . create (
index_type = "hnsw" , dim = 1536 , quantization_config = quantization_config
)
quantized_vector_store = ZeusDBVectorStore (
zeusdb_index = quantized_index , embedding = embeddings
)
print ( f "Created quantized store: { quantized_index . info () } " )
4.2 persistence
Save and load your vector store to disk:
How to Save your vector store
# Save the vector store
vector_store . save_index ( "my_zeusdb_index.zdb" )
How to Load your vector store
# Load the vector store
loaded_store = ZeusDBVectorStore . load_index (
path = "my_zeusdb_index.zdb" , embedding = embeddings
)
print ( f "Loaded store with { loaded_store . get_vector_count () } vectors" )
用于检索增强生成
有关如何将此向量存储用于检索增强生成 (RAG) 的指南,请参阅以下部分:
API 参考
For detailed documentation of all ZeusDBVectorStore features and configurations head to ZeusDB Docs .
连接这些文档 到 Claude、VSCode 等工具,通过 MCP 获取实时答案。