- Vector storage with metadata
- Vector similarity search and max marginal relevance search, with metadata filtering options
- Support for dot production, cosine, and euclidean distance metrics
- Performance optimization by index creation and Approximate nearest neighbors search. (Will be added shortly)
Setup
Prerequisites for using LangChain with Db2 Vector Store and Search
Install packagelangchain-db2 which is the integration package for the db2 LangChain Vector Store and Search.
The installation of the package should also install its dependencies like langchain-core and ibm_db.
Connect to Db2 Vector Store
The following sample code will show how to connect to Db2 Database. Besides the dependencies above, you will need a Db2 database instance (with version v12.1.2+, which has the vector datatype support) running.Import the required dependencies
Initialization
Create Documents
Create Vector Stores with different distance metrics
First we will create three vector stores each with different distance strategies. (You can manually connect to the Db2 Database and will see three tables : Documents_DOT, Documents_COSINE and Documents_EUCLIDEAN. )Manage vector store
Demonstrating add and delete operations for texts, along with basic similarity search
Query vector store
Demonstrate advanced searches on vector stores, with and without attribute filtering
With filtering, we only select the document id 101 and nothing elseUsage for retrieval-augmented generation
API reference
Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.