This package contains the LangChain.js integrations for MongoDB through their SDK.
npm install @langchain/mongodb @langchain/core
This package, along with the main LangChain package, depends on @langchain/core.
If you are using this package with other LangChain packages, you should make sure that all of the packages depend on the same instance of @langchain/core.
You can do so by adding appropriate field to your project's package.json like this:
{
"name": "your-project",
"version": "0.0.0",
"dependencies": {
"@langchain/core": "^0.3.0",
"@langchain/mongodb": "^0.0.0"
},
"resolutions": {
"@langchain/core": "^0.3.0"
},
"overrides": {
"@langchain/core": "^0.3.0"
},
"pnpm": {
"overrides": {
"@langchain/core": "^0.3.0"
}
}
}
The field you need depends on the package manager you're using, but we recommend adding a field for the common yarn, npm, and pnpm to maximize compatibility.
To develop the MongoDB package, you'll need to follow these instructions:
pnpm install
pnpm build
Or from the repo root:
pnpm build --filter @langchain/mongodb
Test files should live within a tests/ file in the src/ folder. Unit tests should end in .test.ts and integration tests should
end in .int.test.ts:
$ pnpm test
$ pnpm test:int
The tests in this package require an instance of MongoDB Atlas running, either running locally or as a remote Atlas cluster. A URI pointing to
an existing Atlas cluster can be provided to the tests by specifying the MONGODB_ATLAS_URI environment variable:
MONGODB_ATLAS_URI='<atlas URI>' pnpm test:int
If running against a remote Atlas cluster, the user must have readWrite permissions on the langchain_test database.
If no MONGODB_ATLAS_URI is provided, the test suite will attempt to launch an instance of local Atlas in a container using testcontainers. This requires a container engine, see the testcontainer backing engine documentation for details.
Run the linter & formatter to ensure your code is up to standard:
pnpm lint && pnpm format
If you add a new file to be exported, either import & re-export from src/index.ts, or add it to the exports field in the package.json file and run pnpm build to generate the new entrypoint.
Class that is a wrapper around MongoDB Atlas Vector Search. It is used to store embeddings in MongoDB documents, create a vector search index, and perform K-Nearest Neighbors (KNN) search with an appr
Class that extends the BaseStore class to interact with a MongoDB database. It provides methods for getting, setting, and deleting data, as well as yielding keys from the database.
A class for generating embeddings using the Voyage AI API.
Interface for the request body to generate embeddings.
Type that defines the arguments required to initialize the MongoDBAtlasVectorSearch class. It includes the MongoDB collection, index name, text key, embedding key, primary key, and overwrite flag.
Type definition for the input parameters required to initialize an instance of the MongoDBStoreInput class.
Interface that extends EmbeddingsParams and defines additional parameters specific to the VoyageEmbeddings class.