VectorX LangChain Integration
This package provides an integration between VectorX (an encrypted vector database) and LangChain, allowing you to use VectorX as a vector store backend for LangChain.
Features
- Encrypted Vector Storage: Use VectorX's client-side encryption for your LangChain embeddings
- Multiple Distance Metrics: Support for cosine, L2, and inner product distance metrics
- Metadata Filtering: Filter search results based on metadata
- High Performance: Optimized for speed and efficiency with encrypted data
Installation
pip install vecx-langchain
This will install both the vecx-langchain package and its dependencies (vecx, langchain, and langchain-core).
Quick Start
import os
from langchain_openai import OpenAIEmbeddings
from langchain_core.documents import Document
from vecx.vectorx import VectorX
from vecx_langchain import VectorXVectorStore
# Configure your VectorX credentials
api_token = os.environ.get("VECTORX_API_TOKEN")
vx = VectorX(token=api_token)
# Generate a secure encryption key
encryption_key = vx.generate_key()
# The key is automatically printed with a warning to store it securely
# Initialize embedding model
embedding_model = OpenAIEmbeddings()
# Initialize the vector store
vector_store = VectorXVectorStore.from_params(
embedding=embedding_model,
api_token=api_token,
encryption_key=encryption_key,
index_name="my_langchain_vectors",
space_type="cosine"
)
# Add documents
texts = [
"VectorX is an encrypted vector database",
"LangChain is a framework for developing applications powered by language models",
"Encryption keeps your data secure"
]
metadatas = [
{"source": "product", "category": "database"},
{"source": "github", "category": "framework"},
{"source": "textbook", "category": "security"}
]
vector_store.add_texts(texts=texts, metadatas=metadatas)
# Search similar documents
results = vector_store.similarity_search("How does encryption work?", k=2)
# Process results
for doc in results:
print(f"Content: {doc.page_content}")
print(f"Metadata: {doc.metadata}")
print()
How Encryption Works
When using the VectorX LangChain integration:
- Key Generation: The
vx.generate_key()method generates a secure encryption key - Client-Side Encryption: Your vectors and metadata are encrypted before being sent to the server
- Secure Queries: Query vectors are also encrypted, maintaining security throughout the process
- Zero-Knowledge Architecture: The VectorX server never sees your unencrypted data
Using with LangChain
VectorX can be used anywhere a LangChain vector store is needed:
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
from vecx_langchain import VectorXVectorStore
# Initialize your vector store
vector_store = VectorXVectorStore.from_params(
embedding=OpenAIEmbeddings(),
api_token="your_api_token",
encryption_key="your_encryption_key",
index_name="your_index_name"
)
# Create a retriever
retriever = vector_store.as_retriever()
# Create the RAG chain
model = ChatOpenAI()
prompt = ChatPromptTemplate.from_template(
"""Answer the following question based on the provided context:
Context: {context}
Question: {question}
"""
)
rag_chain = (
{"context": retriever, "question": RunnablePassthrough()}
| prompt
| model
| StrOutputParser()
)
# Use the chain
response = rag_chain.invoke("What is VectorX?")
print(response)
API Reference
VectorXVectorStore
The main class for integrating with LangChain. Key methods include:
__init__: Initialize with a VectorX index or parameters to create a new onefrom_params: Create a vector store using an API token and encryption keyadd_texts: Add text documents with optional metadatasimilarity_search: Search for similar documentssimilarity_search_with_score: Search and return similarity scoresdelete: Delete documents by ID or filter
Configuration Options
The VectorXVectorStore constructor and from_params method accept the following parameters:
embedding: LangChain embedding function to useapi_token: Your VectorX API tokenencryption_key: Your encryption key for the indexindex_name: Name of the VectorX indexdimension: Vector dimension (can be inferred from embedding model)space_type: Distance metric, one of "cosine", "l2", or "ip" (default: "cosine")text_key: Key to use for storing text in metadata (default: "text")
Release files for vecx-langchain 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| vecx_langchain-0.1.3.tar.gz | 6.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| vecx_langchain-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.1 kB
Release files / vecx_langchain-0.1.3.tar.gz
| Download URL | vecx_langchain-0.1.3.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f2ea444899743cfe991e240604ccea812eb1fa11730788a9ab9a6ec993f5847d
|
|
BLAKE2b-256 checksum How to use checksums |
0da4de0466f493d689dba8ba420dcf047d5b092e66c7f58f20a306bb128b9442
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.11
|
Release files / vecx_langchain-0.1.3-py3-none-any.whl
| Download URL | vecx_langchain-0.1.3-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eb758edf57d596d1a441a9a1c7abc4785a1d86a07107de9e4ccc199a0114e57a
|
|
BLAKE2b-256 checksum How to use checksums |
cc92a333eabca302c89fd67dd694d71d4af10522ecc372aafcfd6f111ceab52d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.11
|