Skip to main content
LangChain is a framework for developing applications powered by Large Language Models. It unifies interfaces to various embedding providers and vector stores. Actian VectorAI DB integrates with LangChain as a vector store through the 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:
This package includes 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

  • Python 3.10 or later
  • A running Actian VectorAI DB instance (default endpoint: localhost:6574). See Docker installation for setup instructions.
  • An OPENAI_API_KEY environment variable set with a valid OpenAI API key, if using OpenAIEmbeddings as 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. The ActianVectorAIVectorStore 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 LangChain Document 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

Use from_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

Use from_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 use AsyncVectorAIClient 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

Use afrom_texts to create a vector store and add texts asynchronously. The returned store supports all async operations, including asimilarity_search.

Async from documents

Use afrom_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.
Use similarity_search to return the k most similar documents to a query.

Search with scores

Use similarity_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

Use similarity_search_with_relevance_scores to return documents with scores normalized to a zero-to-one range, where higher values indicate greater relevance.
All search methods have async variants prefixed with a.
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.

Use as a retriever

You can convert the vector store into a LangChain retriever for use in chains and agents. The search_type parameter accepts "similarity" for standard vector search or "mmr" for Max Marginal Relevance search. Pass additional search parameters through search_kwargs.

Configuration

API reference

Next steps

  • LlamaIndex — Alternative framework for RAG applications.
  • Search — Understand the underlying vector search operations.
  • Filtering — Apply metadata conditions to narrow search results.