mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-01 19:03:25 +00:00
partners[patch]: MongoDB vectorstore to return and accept string IDs (#23818)
The mongdb have some errors. - `add_texts() -> List` returns a list of `ObjectId`, and not a list of string - `delete()` with `id` never remove chunks. --------- Co-authored-by: Eugene Yurtsev <eugene@langchain.dev>
This commit is contained in:
parent
75734fbcf1
commit
26cee2e878
@ -144,7 +144,7 @@ class MongoDBAtlasVectorSearch(VectorStore):
|
|||||||
texts: Iterable[str],
|
texts: Iterable[str],
|
||||||
metadatas: Optional[List[Dict[str, Any]]] = None,
|
metadatas: Optional[List[Dict[str, Any]]] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> List:
|
) -> List[str]:
|
||||||
"""Run more texts through the embeddings and add to the vectorstore.
|
"""Run more texts through the embeddings and add to the vectorstore.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -174,7 +174,7 @@ class MongoDBAtlasVectorSearch(VectorStore):
|
|||||||
size = 0
|
size = 0
|
||||||
if texts_batch:
|
if texts_batch:
|
||||||
result_ids.extend(self._insert_texts(texts_batch, metadatas_batch)) # type: ignore
|
result_ids.extend(self._insert_texts(texts_batch, metadatas_batch)) # type: ignore
|
||||||
return result_ids
|
return [str(id) for id in result_ids]
|
||||||
|
|
||||||
def _insert_texts(self, texts: List[str], metadatas: List[Dict[str, Any]]) -> List:
|
def _insert_texts(self, texts: List[str], metadatas: List[Dict[str, Any]]) -> List:
|
||||||
if not texts:
|
if not texts:
|
||||||
@ -410,7 +410,7 @@ class MongoDBAtlasVectorSearch(VectorStore):
|
|||||||
"""
|
"""
|
||||||
search_params: dict[str, Any] = {}
|
search_params: dict[str, Any] = {}
|
||||||
if ids:
|
if ids:
|
||||||
search_params[self._text_key]["$in"] = ids
|
search_params["_id"] = {"$in": [ObjectId(id) for id in ids]}
|
||||||
|
|
||||||
return self._collection.delete_many({**search_params, **kwargs}).acknowledged
|
return self._collection.delete_many({**search_params, **kwargs}).acknowledged
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user