Vector Stores API Reference
The empire_chain.vector_stores
module provides interfaces to various vector databases for efficient similarity search.
QdrantVectorStore
Class for interacting with Qdrant vector database.
Constructor
Parameters:
- location
(str): Location of the Qdrant database
- :memory:
for in-memory storage
- URL or path for persistent storage
- collection_name
(str): Name of the collection to use
Methods
add()
Add text and its embedding to the store.
Parameters:
- text
(str): The text to store
- embedding
(List[float]): Vector representation of the text
Example:
query()
Retrieve similar texts based on embedding.
Parameters:
- embedding
(List[float]): Query vector
- k
(int): Number of results to return
Returns: - List[str]: List of similar texts
Example:
delete()
Delete entries by their IDs.
Parameters:
- ids
(List[str]): List of IDs to delete
clear()
Clear all entries from the store.
ChromaVectorStore
Class for interacting with ChromaDB.
Constructor
Parameters:
- path
(Optional[str]): Path for persistent storage
- collection_name
(str): Name of the collection
Methods
add()
Add text and its embedding to ChromaDB.
Parameters:
- text
(str): The text to store
- embedding
(List[float]): Vector representation of the text
Example:
query()
Retrieve similar texts from ChromaDB.
Parameters:
- embedding
(List[float]): Query vector
- k
(int): Number of results to return
Returns: - List[str]: List of similar texts
Example:
Common Usage Patterns
Basic RAG Setup
from empire_chain.vector_stores import QdrantVectorStore
from empire_chain.embeddings import OpenAIEmbeddings
# Initialize components
store = QdrantVectorStore(":memory:")
embeddings = OpenAIEmbeddings("text-embedding-3-small")
# Add documents
text = "Your document text here"
embedding = embeddings.embed(text)
store.add(text, embedding)
# Query
query = "Your query here"
query_embedding = embeddings.embed(query)
results = store.query(query_embedding, k=3)
Persistent Storage
# Qdrant with persistent storage
qdrant_store = QdrantVectorStore(
location="path/to/storage",
collection_name="my_documents"
)
# ChromaDB with persistent storage
chroma_store = ChromaVectorStore(
path="path/to/storage",
collection_name="my_documents"
)
Error Handling
try:
store = QdrantVectorStore(":memory:")
store.add(text, embedding)
except Exception as e:
print(f"Error: {e}")
Best Practices
-
Memory Management
-
Batch Operations
-
Collection Management