-
Couldn't load subscription status.
- Fork 1.2k
feat: mongodb vector io #3772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
seyeong-han
wants to merge
8
commits into
llamastack:main
Choose a base branch
from
seyeong-han:add-mongodb-vector_io
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: mongodb vector io #3772
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dd1136a
init: add mongodb in vector_io
seyeong-han aa21996
fix: add missing __init__.py files for vector_io test directories
seyeong-han 2b6d57a
fix: add missing __init__.py files for vector_io test directories
seyeong-han d8c82c1
Merge remote-tracking branch 'upstream/main' into add-mongodb-vector_io
seyeong-han 885631d
feat: add mongodb provider
seyeong-han 572062d
fix: resolve unit test failures in starter distribution with MongoDB …
seyeong-han efe9c04
Merge upstream/main into add-mongodb-vector_io
seyeong-han 9d73207
fix: apply pre-commit hook auto-fixes and resolve mypy errors
seyeong-han File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,268 @@ | ||
| --- | ||
| description: | | ||
| [MongoDB Atlas](https://www.mongodb.com/products/platform/atlas-vector-search) is a remote vector database provider for Llama Stack. It | ||
| uses MongoDB Atlas Vector Search to store and query vectors in the cloud. | ||
| That means you get enterprise-grade vector search with MongoDB's scalability and reliability. | ||
|
|
||
| ## Features | ||
|
|
||
| - Cloud-native vector search with MongoDB Atlas | ||
| - Fully integrated with Llama Stack | ||
| - Enterprise-grade security and scalability | ||
| - Supports multiple search modes: vector, keyword, and hybrid search | ||
| - Built-in metadata filtering and text search capabilities | ||
| - Automatic index management | ||
|
|
||
| ## Search Modes | ||
|
|
||
| MongoDB Atlas Vector Search supports three different search modes: | ||
|
|
||
| ### Vector Search | ||
| Vector search uses MongoDB's `$vectorSearch` aggregation stage to perform semantic similarity search using embedding vectors. | ||
|
|
||
| ```python | ||
| # Vector search example | ||
| search_response = client.vector_stores.search( | ||
| vector_store_id=vector_store.id, | ||
| query="What is machine learning?", | ||
| search_mode="vector", | ||
| max_num_results=5, | ||
| ) | ||
| ``` | ||
|
|
||
| ### Keyword Search | ||
| Keyword search uses MongoDB's text search capabilities with full-text indexes to find chunks containing specific terms. | ||
|
|
||
| ```python | ||
| # Keyword search example | ||
| search_response = client.vector_stores.search( | ||
| vector_store_id=vector_store.id, | ||
| query="Python programming language", | ||
| search_mode="keyword", | ||
| max_num_results=5, | ||
| ) | ||
| ``` | ||
|
|
||
| ### Hybrid Search | ||
| Hybrid search combines both vector and keyword search methods using configurable reranking algorithms. | ||
|
|
||
| ```python | ||
| # Hybrid search with RRF ranker (default) | ||
| search_response = client.vector_stores.search( | ||
| vector_store_id=vector_store.id, | ||
| query="neural networks in Python", | ||
| search_mode="hybrid", | ||
| max_num_results=5, | ||
| ) | ||
|
|
||
| # Hybrid search with weighted ranker | ||
| search_response = client.vector_stores.search( | ||
| vector_store_id=vector_store.id, | ||
| query="neural networks in Python", | ||
| search_mode="hybrid", | ||
| max_num_results=5, | ||
| ranking_options={ | ||
| "ranker": { | ||
| "type": "weighted", | ||
| "alpha": 0.7, # 70% vector search, 30% keyword search | ||
| } | ||
| }, | ||
| ) | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| To use MongoDB Atlas in your Llama Stack project, follow these steps: | ||
|
|
||
| 1. Create a MongoDB Atlas cluster with Vector Search enabled | ||
| 2. Install the necessary dependencies | ||
| 3. Configure your Llama Stack project to use MongoDB | ||
| 4. Start storing and querying vectors | ||
|
|
||
| ## Configuration | ||
|
|
||
| ### Environment Variables | ||
| Set up the following environment variable for your MongoDB Atlas connection: | ||
|
|
||
| ```bash | ||
| export MONGODB_CONNECTION_STRING="mongodb+srv://username:[email protected]/?retryWrites=true&w=majority&appName=llama-stack" | ||
| ``` | ||
|
|
||
| ### Configuration Example | ||
|
|
||
| ```yaml | ||
| vector_io: | ||
| - provider_id: mongodb_atlas | ||
| provider_type: remote::mongodb | ||
| config: | ||
| connection_string: "${env.MONGODB_CONNECTION_STRING}" | ||
| database_name: "llama_stack" | ||
| index_name: "vector_index" | ||
| similarity_metric: "cosine" | ||
| ``` | ||
|
|
||
| ## Installation | ||
|
|
||
| You can install the MongoDB Python driver using pip: | ||
|
|
||
| ```bash | ||
| pip install pymongo | ||
| ``` | ||
|
|
||
| ## Documentation | ||
|
|
||
| See [MongoDB Atlas Vector Search documentation](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-overview/) for more details about MongoDB Atlas Vector Search. | ||
|
|
||
| For general MongoDB documentation, visit [MongoDB Documentation](https://docs.mongodb.com/). | ||
| sidebar_label: Remote - Mongodb | ||
| title: remote::mongodb | ||
| --- | ||
|
|
||
| # remote::mongodb | ||
|
|
||
| ## Description | ||
|
|
||
|
|
||
| [MongoDB Atlas](https://www.mongodb.com/products/platform/atlas-vector-search) is a remote vector database provider for Llama Stack. It | ||
| uses MongoDB Atlas Vector Search to store and query vectors in the cloud. | ||
| That means you get enterprise-grade vector search with MongoDB's scalability and reliability. | ||
|
|
||
| ## Features | ||
|
|
||
| - Cloud-native vector search with MongoDB Atlas | ||
| - Fully integrated with Llama Stack | ||
| - Enterprise-grade security and scalability | ||
| - Supports multiple search modes: vector, keyword, and hybrid search | ||
| - Built-in metadata filtering and text search capabilities | ||
| - Automatic index management | ||
|
|
||
| ## Search Modes | ||
|
|
||
| MongoDB Atlas Vector Search supports three different search modes: | ||
|
|
||
| ### Vector Search | ||
| Vector search uses MongoDB's `$vectorSearch` aggregation stage to perform semantic similarity search using embedding vectors. | ||
|
|
||
| ```python | ||
| # Vector search example | ||
| search_response = client.vector_stores.search( | ||
| vector_store_id=vector_store.id, | ||
| query="What is machine learning?", | ||
| search_mode="vector", | ||
| max_num_results=5, | ||
| ) | ||
| ``` | ||
|
|
||
| ### Keyword Search | ||
| Keyword search uses MongoDB's text search capabilities with full-text indexes to find chunks containing specific terms. | ||
|
|
||
| ```python | ||
| # Keyword search example | ||
| search_response = client.vector_stores.search( | ||
| vector_store_id=vector_store.id, | ||
| query="Python programming language", | ||
| search_mode="keyword", | ||
| max_num_results=5, | ||
| ) | ||
| ``` | ||
|
|
||
| ### Hybrid Search | ||
| Hybrid search combines both vector and keyword search methods using configurable reranking algorithms. | ||
|
|
||
| ```python | ||
| # Hybrid search with RRF ranker (default) | ||
| search_response = client.vector_stores.search( | ||
| vector_store_id=vector_store.id, | ||
| query="neural networks in Python", | ||
| search_mode="hybrid", | ||
| max_num_results=5, | ||
| ) | ||
|
|
||
| # Hybrid search with weighted ranker | ||
| search_response = client.vector_stores.search( | ||
| vector_store_id=vector_store.id, | ||
| query="neural networks in Python", | ||
| search_mode="hybrid", | ||
| max_num_results=5, | ||
| ranking_options={ | ||
| "ranker": { | ||
| "type": "weighted", | ||
| "alpha": 0.7, # 70% vector search, 30% keyword search | ||
| } | ||
| }, | ||
| ) | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| To use MongoDB Atlas in your Llama Stack project, follow these steps: | ||
|
|
||
| 1. Create a MongoDB Atlas cluster with Vector Search enabled | ||
| 2. Install the necessary dependencies | ||
| 3. Configure your Llama Stack project to use MongoDB | ||
| 4. Start storing and querying vectors | ||
|
|
||
| ## Configuration | ||
|
|
||
| ### Environment Variables | ||
| Set up the following environment variable for your MongoDB Atlas connection: | ||
|
|
||
| ```bash | ||
| export MONGODB_CONNECTION_STRING="mongodb+srv://username:[email protected]/?retryWrites=true&w=majority&appName=llama-stack" | ||
| ``` | ||
|
|
||
| ### Configuration Example | ||
|
|
||
| ```yaml | ||
| vector_io: | ||
| - provider_id: mongodb_atlas | ||
| provider_type: remote::mongodb | ||
| config: | ||
| connection_string: "${env.MONGODB_CONNECTION_STRING}" | ||
| database_name: "llama_stack" | ||
| index_name: "vector_index" | ||
| similarity_metric: "cosine" | ||
| ``` | ||
|
|
||
| ## Installation | ||
|
|
||
| You can install the MongoDB Python driver using pip: | ||
|
|
||
| ```bash | ||
| pip install pymongo | ||
| ``` | ||
|
|
||
| ## Documentation | ||
|
|
||
| See [MongoDB Atlas Vector Search documentation](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-overview/) for more details about MongoDB Atlas Vector Search. | ||
|
|
||
| For general MongoDB documentation, visit [MongoDB Documentation](https://docs.mongodb.com/). | ||
|
|
||
|
|
||
| ## Configuration | ||
|
|
||
| | Field | Type | Required | Default | Description | | ||
| |-------|------|----------|---------|-------------| | ||
| | `connection_string` | `<class 'str'>` | No | | MongoDB Atlas connection string (e.g., mongodb+srv://user:[email protected]/) | | ||
| | `database_name` | `<class 'str'>` | No | llama_stack | Database name to use for vector collections | | ||
| | `index_name` | `<class 'str'>` | No | vector_index | Name of the vector search index | | ||
| | `path_field` | `<class 'str'>` | No | embedding | Field name for storing embeddings | | ||
| | `similarity_metric` | `<class 'str'>` | No | cosine | Similarity metric: cosine, euclidean, or dotProduct | | ||
| | `max_pool_size` | `<class 'int'>` | No | 100 | Maximum connection pool size | | ||
| | `timeout_ms` | `<class 'int'>` | No | 30000 | Connection timeout in milliseconds | | ||
| | `kvstore` | `utils.kvstore.config.RedisKVStoreConfig \| utils.kvstore.config.SqliteKVStoreConfig \| utils.kvstore.config.PostgresKVStoreConfig \| utils.kvstore.config.MongoDBKVStoreConfig` | No | sqlite | Config for KV store backend for metadata storage | | ||
|
|
||
| ## Sample Configuration | ||
|
|
||
| ```yaml | ||
| connection_string: ${env.MONGODB_CONNECTION_STRING:=} | ||
| database_name: ${env.MONGODB_DATABASE_NAME:=llama_stack} | ||
| index_name: ${env.MONGODB_INDEX_NAME:=vector_index} | ||
| path_field: ${env.MONGODB_PATH_FIELD:=embedding} | ||
| similarity_metric: ${env.MONGODB_SIMILARITY_METRIC:=cosine} | ||
| max_pool_size: ${env.MONGODB_MAX_POOL_SIZE:=100} | ||
| timeout_ms: ${env.MONGODB_TIMEOUT_MS:=30000} | ||
| kvstore: | ||
| type: sqlite | ||
| db_path: ${env.SQLITE_STORE_DIR:=~/.llama/dummy}/mongodb_registry.db | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,9 @@ | |
| ) | ||
| from llama_stack.providers.registry.inference import available_providers | ||
| from llama_stack.providers.remote.vector_io.chroma.config import ChromaVectorIOConfig | ||
| from llama_stack.providers.remote.vector_io.mongodb.config import ( | ||
| MongoDBVectorIOConfig, | ||
| ) | ||
| from llama_stack.providers.remote.vector_io.pgvector.config import ( | ||
| PGVectorVectorIOConfig, | ||
| ) | ||
|
|
@@ -113,6 +116,7 @@ def get_distribution_template(name: str = "starter") -> DistributionTemplate: | |
| BuildProvider(provider_type="inline::milvus"), | ||
| BuildProvider(provider_type="remote::chromadb"), | ||
| BuildProvider(provider_type="remote::pgvector"), | ||
| BuildProvider(provider_type="remote::mongodb"), | ||
| ], | ||
| "files": [BuildProvider(provider_type="inline::localfs")], | ||
| "safety": [ | ||
|
|
@@ -222,6 +226,13 @@ def get_distribution_template(name: str = "starter") -> DistributionTemplate: | |
| password="${env.PGVECTOR_PASSWORD:=}", | ||
| ), | ||
| ), | ||
| Provider( | ||
| provider_id="${env.MONGODB_CONNECTION_STRING:+mongodb_atlas}", | ||
| provider_type="remote::mongodb", | ||
| config=MongoDBVectorIOConfig.sample_run_config( | ||
| f"~/.llama/distributions/{name}", | ||
| ), | ||
| ), | ||
| ], | ||
| "files": [files_provider], | ||
| }, | ||
|
|
@@ -295,5 +306,13 @@ def get_distribution_template(name: str = "starter") -> DistributionTemplate: | |
| "azure", | ||
| "Azure API Type", | ||
| ), | ||
| "MONGODB_CONNECTION_STRING": ( | ||
| "", | ||
| "MongoDB Atlas connection string (e.g., mongodb+srv://user:[email protected]/)", | ||
| ), | ||
| "MONGODB_DATABASE_NAME": ( | ||
| "llama_stack", | ||
| "MongoDB database name", | ||
| ), | ||
| }, | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think part of this readme is duplicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the
# Usageand# Configurationsections are duplicated.