mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-03 18:00:36 +00:00
fix: Config can be instantiated with without validation errors
This commit is contained in:
parent
8f0f4a26a3
commit
cac2912ce6
4 changed files with 16 additions and 5 deletions
|
|
@ -243,7 +243,7 @@ For general MongoDB documentation, visit [MongoDB Documentation](https://docs.mo
|
|||
|
||||
| Field | Type | Required | Default | Description |
|
||||
|-------|------|----------|---------|-------------|
|
||||
| `connection_string` | `<class 'str'>` | No | | MongoDB Atlas connection string (e.g., mongodb+srv://user:pass@cluster.mongodb.net/) |
|
||||
| `connection_string` | `str \| None` | No | | MongoDB Atlas connection string (e.g., mongodb+srv://user:pass@cluster.mongodb.net/) |
|
||||
| `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 |
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ async def get_adapter_impl(config: MongoDBVectorIOConfig, deps: dict[Api, Provid
|
|||
|
||||
# Handle the deps resolution - if files API exists, pass it, otherwise None
|
||||
files_api = deps.get(Api.files)
|
||||
impl = MongoDBVectorIOAdapter(config, deps[Api.inference], files_api)
|
||||
models_api = deps.get(Api.models)
|
||||
impl = MongoDBVectorIOAdapter(config, deps[Api.inference], files_api, models_api)
|
||||
await impl.initialize()
|
||||
return impl
|
||||
|
|
|
|||
|
|
@ -20,8 +20,9 @@ class MongoDBVectorIOConfig(BaseModel):
|
|||
"""
|
||||
|
||||
# MongoDB Atlas connection details
|
||||
connection_string: str = Field(
|
||||
description="MongoDB Atlas connection string (e.g., mongodb+srv://user:pass@cluster.mongodb.net/)"
|
||||
connection_string: str | None = Field(
|
||||
default=None,
|
||||
description="MongoDB Atlas connection string (e.g., mongodb+srv://user:pass@cluster.mongodb.net/)",
|
||||
)
|
||||
database_name: str = Field(default="llama_stack", description="Database name to use for vector collections")
|
||||
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ class MongoDBIndex(EmbeddingIndex):
|
|||
"index": self.config.index_name,
|
||||
"queryVector": embedding.tolist(),
|
||||
"path": self.config.path_field,
|
||||
"numCandidates": k * 10, # Get more candidates for better results
|
||||
"numCandidates": min(k * 10, 1000), # Cap at 1000 to prevent excessive candidates
|
||||
"limit": k,
|
||||
}
|
||||
},
|
||||
|
|
@ -398,12 +398,14 @@ class MongoDBVectorIOAdapter(OpenAIVectorStoreMixin, VectorIO, VectorStoresProto
|
|||
config: MongoDBVectorIOConfig,
|
||||
inference_api,
|
||||
files_api=None,
|
||||
models_api=None,
|
||||
) -> None:
|
||||
# Handle the case where files_api might be a ProviderSpec that needs resolution
|
||||
resolved_files_api = files_api
|
||||
super().__init__(files_api=resolved_files_api, kvstore=None)
|
||||
self.config = config
|
||||
self.inference_api = inference_api
|
||||
self.models_api = models_api
|
||||
self.client: MongoClient | None = None
|
||||
self.database: Database | None = None
|
||||
self.cache: dict[str, VectorStoreWithIndex] = {}
|
||||
|
|
@ -418,6 +420,13 @@ class MongoDBVectorIOAdapter(OpenAIVectorStoreMixin, VectorIO, VectorStoresProto
|
|||
if self.config.persistence:
|
||||
self.kvstore = await kvstore_impl(self.config.persistence)
|
||||
|
||||
# Validate connection string
|
||||
if not self.config.connection_string:
|
||||
raise ValueError(
|
||||
"MongoDB connection_string is required but not provided. "
|
||||
"Please set MONGODB_CONNECTION_STRING environment variable or provide it in config."
|
||||
)
|
||||
|
||||
# Connect to MongoDB with optimized settings for RAG
|
||||
self.client = MongoClient(
|
||||
self.config.connection_string,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue