langchain-actian-vectorai package. This integration supports all standard LangChain vector store operations, including adding documents, similarity search, max marginal relevance search, and using VectorAI DB as a retriever in LangChain chains.
Installation
Install the VectorAI DB vector store integration for LangChain:actian_vectorai as a transitive dependency, so you do not need to install it separately.
You also need an embedding provider such as langchain-openai:
Requirements
Before using this integration, make sure your environment meets the following prerequisites:- Python 3.10 or later
- A running Actian VectorAI DB instance (default endpoint:
localhost:50051). See Docker installation for setup instructions. - An
OPENAI_API_KEYenvironment variable set with a valid OpenAI API key, if usingOpenAIEmbeddingsas your embedding provider.
Quickstart
The following example connects to a VectorAI DB server, creates a collection with cosine distance, adds two texts, and runs a similarity search. TheActianVectorAIVectorStore handles embedding generation and vector storage automatically. The vector dimension is set to 1536 to match the default OpenAIEmbeddings model.
Creating a vector store
You can create a vector store from plain text strings or from LangChainDocument objects. Both methods handle collection creation and vector insertion in a single call. Use these helper constructors when you want automatic setup. Use the manual approach shown in the Quickstart when you need explicit control over collection parameters such as vector dimension or distance metric.
From texts
Usefrom_texts to create a vector store, set up a collection, and add texts in a single call. The metadatas parameter attaches metadata to each text as payload in VectorAI DB, which you can use for filtering during search.
From documents
Usefrom_documents to create a vector store from LangChain Document objects. The page_content field is embedded and stored as a vector, and the metadata field is stored as payload in VectorAI DB.
Async operations
All creation and search methods have async counterparts for non-blocking operations. Async methods useAsyncVectorAIClient under the hood. The await calls in this section must run inside an async function or an environment that supports top level await, such as a Jupyter notebook.
Async from texts
Useafrom_texts to create a vector store and add texts asynchronously. The returned store supports all async operations, including asimilarity_search.
Async from documents
Useafrom_documents to create a vector store from Document objects asynchronously. Document IDs are preserved when set, and you can use adelete to remove documents by ID.
Similarity search
The integration provides several similarity search methods, each available in both sync and async variants.Basic search
Usesimilarity_search to return the k most similar documents to a query.
Search with scores
Usesimilarity_search_with_score to return documents paired with their raw similarity scores. Lower scores indicate closer matches when using cosine distance.
Search with relevance scores
Usesimilarity_search_with_relevance_scores to return documents with scores normalized to a zero-to-one range, where higher values indicate greater relevance.
Async search
All search methods have async variants prefixed witha.
Max Marginal Relevance search
Max Marginal Relevance (MMR) optimizes for both similarity to the query and diversity among results. This is useful when you want relevant results that cover different aspects of the query rather than returning near-duplicate matches. The following table describes the MMR-specific parameters.| Parameter | Description |
|---|---|
k | Number of results to return. |
fetch_k | Number of candidates to fetch before reranking. Higher values give MMR more candidates to select from. |
lambda_mult | Balance between relevance and diversity. Values closer to 1.0 favor relevance, values closer to 0.0 favor diversity. |
lambda_mult value of 0.5 balances relevance and diversity equally.
Use as a retriever
You can convert the vector store into a LangChain retriever for use in chains and agents. Thesearch_type parameter accepts "similarity" for standard vector search or "mmr" for Max Marginal Relevance search. Pass additional search parameters through search_kwargs.
Configuration
The following table lists the parameters you can pass when creating anActianVectorAIVectorStore instance.
| Parameter | Default | Description |
|---|---|---|
url | "localhost:50051" | VectorAI server gRPC address. |
collection_name | Auto-generated UUID | Collection name in VectorAI DB. |
distance | "COSINE" | Distance metric: COSINE, EUCLID, or DOT. |
content_payload_key | "page_content" | Payload key for document content. |
metadata_payload_key | "metadata" | Payload key for document metadata. |
batch_size | 64 | Batch size for upsert operations. |
force_recreate | False | Recreate collection if it already exists. |
API reference
The following table lists all available methods onActianVectorAIVectorStore and their async counterparts.
| Method | Async variant | Description |
|---|---|---|
from_texts() | afrom_texts() | Create store, collection, and add texts. |
from_documents() | afrom_documents() | Create store, collection, and add documents. |
add_texts() | aadd_texts() | Add texts to an existing store. |
add_documents() | aadd_documents() | Add documents to an existing store. |
similarity_search() | asimilarity_search() | Search by query text. |
similarity_search_with_score() | asimilarity_search_with_score() | Search with raw scores. |
similarity_search_by_vector() | asimilarity_search_by_vector() | Search by embedding vector. |
max_marginal_relevance_search() | amax_marginal_relevance_search() | MMR search for diverse results. |
delete() | adelete() | Delete documents by IDs. |
get_by_ids() | aget_by_ids() | Retrieve documents by IDs. |
Next steps
Explore related topics to continue building with LangChain and VectorAI DB:- OpenAI embeddings — Configure OpenAI as your embedding provider.
- LlamaIndex — Use VectorAI DB with the LlamaIndex framework.
- Search — Understand the underlying vector search operations.
- Filtering — Apply metadata conditions to narrow search results.