Skip to content

Commit b35eab0

Browse files
WaVEVJibolacaseyclements
authored
Feature/mongodb datastore (#2)
Add MongoDB as a datastore with Atlas Vector Search. Detailed setup: docs/providers/mongodb/setup.md Example notebook: examples/providers/mongodb/semantic-search.ipynb Integration tests: tests/datastore/providers/mongodb_atlas/test_mongodb_datastore.py Documentation has also been updated. --------- Co-authored-by: Jib <[email protected]> Co-authored-by: Casey Clements <[email protected]>
1 parent 3012eba commit b35eab0

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

datastore/providers/mongodb_atlas_datastore.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
MONGODB_INDEX = os.environ.get("MONGODB_INDEX", "default")
2626
OVERSAMPLING_FACTOR = 10
2727
MAX_CANDIDATES = 10_000
28-
UPSERT_BATCH_SIZE = 100
2928

3029

3130
class MongoDBAtlasDataStore(DataStore):
@@ -88,7 +87,7 @@ async def _upsert(self, chunks: Dict[str, List[DocumentChunk]]) -> List[str]:
8887
self._convert_document_chunk_to_mongodb_document(chunk)
8988
)
9089
# Upsert documents into the MongoDB collection
91-
logger.info(f"{self.database_name}: {self.collection_name}")
90+
logger.info(f"Upsert into: {self.database_name}: {self.collection_name}")
9291
await self.client[self.database_name][self.collection_name].insert_many(
9392
documents_to_upsert
9493
)
@@ -137,11 +136,11 @@ async def _execute_embedding_query(self, query: QueryWithEmbedding) -> QueryResu
137136
}
138137
]
139138

140-
cursor = self.client[self.database_name][self.collection_name].aggregate(pipeline)
141-
results = [
142-
self._convert_mongodb_document_to_document_chunk_with_score(doc)
143-
async for doc in cursor
144-
]
139+
async with self.client[self.database_name][self.collection_name].aggregate(pipeline) as cursor:
140+
results = [
141+
self._convert_mongodb_document_to_document_chunk_with_score(doc)
142+
async for doc in cursor
143+
]
145144

146145
return QueryResult(
147146
query=query.query,

0 commit comments

Comments
 (0)