> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-5e9cc07a-preview-opensw-1782332329-96d87c7.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# ZeusDB integration

> Integrate with the ZeusDB vector store using LangChain Python.

> [ZeusDB](https://www.zeusdb.com) 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.

***

## Setup

Install the ZeusDB LangChain integration package from PyPI:

```python theme={null}
pip install -qU langchain-zeusdb
```

Setup in Jupyter Notebooks

```python theme={null}
pip install -qU langchain-zeusdb
```

***

## Getting started

This example uses OpenAIEmbeddings, which requires an OpenAI API key: [Get your OpenAI API key here](https://platform.openai.com/api-keys)
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:

```python theme={null}
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:

```python theme={null}
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

```python theme={null}
from dotenv import load_dotenv

load_dotenv()  # reads .env and sets OPENAI_API_KEY
```

<Info>
  🎉 Nicely done! You are good to go.
</Info>

***

## Initialization

```python theme={null}
# Import required Packages and Classes
from langchain_zeusdb import ZeusDBVectorStore
from langchain_openai import OpenAIEmbeddings
from zeusdb import VectorDatabase
```

```python theme={null}
# 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)
```

***

## Manage vector store

### 2.1 add items to vector store

```python theme={null}
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

```python theme={null}
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

```python theme={null}
vector_store.delete(ids=["3"])
```

***

## Query vector store

### 3.1 query directly

Performing a simple similarity search:

```python theme={null}
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:

```python theme={null}
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:

```python theme={null}
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:

```python theme={null}
# 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

```python theme={null}
# Save the vector store
vector_store.save_index("my_zeusdb_index.zdb")
```

How to Load your vector store

```python theme={null}
# 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")
```

***

## Usage for retrieval-augmented generation

For guides on how to use this vector store for retrieval-augmented generation (RAG), see the following sections:

* [Retrieval docs](/oss/python/langchain/retrieval)
* [Build a RAG app with LangChain](/oss/python/langchain/rag)
* [Agentic RAG](/oss/python/langgraph/agentic-rag)

***

## API reference

For detailed documentation of all `ZeusDBVectorStore` features and configurations head to [ZeusDB Docs](https://docs.zeusdb.com/en/latest/vector_database/integrations/langchain.html).

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/vectorstores/zeusdb.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
