Skip to main content
YDB is a versatile open source Distributed SQL Database that combines high availability and scalability with strong consistency and ACID transactions. It accommodates transactional (OLTP), analytical (OLAP), and streaming workloads simultaneously.
This guide provides a quick overview for getting started with the YDBVectorStore vector store. For detailed documentation of all features and configurations, head to the YDB LangChain.js guide.

Setup

Set up a local YDB instance with Docker:
Install @ydbjs/langchain and @langchain/core to use this integration. This guide uses OpenAI embeddings as an example. You can use other supported embeddings models instead.

Credentials

There are no credentials required for a local YDB instance. Make sure you have installed the packages shown above. If you are using OpenAI embeddings for this guide, set your OpenAI key:
If you want to get automated tracing of your model calls, you can also set your LangSmith API key by uncommenting below:

Instantiation

To instantiate the vector store, pass an embeddings model and a connection string. When the store creates the driver, it also manages its lifecycle:
The await using syntax automatically disposes of the store and closes its driver when the variable goes out of scope. If you do not use await using, call close() manually when you are finished:

Manage vector store

Add items to vector store

Add documents using the addDocuments method. Documents without an ID receive auto-generated UUIDs, and re-inserting a document with an existing ID replaces it.

Delete items from vector store

Delete specific documents by ID:

Query vector store

Once your vector store has been created and the relevant documents have been added, you will most likely wish to query it during the running of your chain or agent.

Query directly

Perform a simple similarity search as follows:
To execute a similarity search and receive the corresponding scores, run:
You can also filter results by metadata. Filters are passed as key-value pairs and combined with AND logic:

Query by turning into retriever

You can also transform the vector store into a retriever for easier usage in your chains:

Usage for retrieval-augmented generation

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

API reference

For detailed documentation of all YDBVectorStore features and configurations, including search strategies, approximate nearest-neighbor indexing, and column customization, head to the YDB LangChain.js guide.