Skip to content

Commit

Permalink
partners[patch]: MongoDB vectorstore to return and accept string IDs (#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
pprados and eyurtsev authored Jul 3, 2024
1 parent 75734fb commit 26cee2e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions libs/partners/mongodb/langchain_mongodb/vectorstores.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def add_texts(
texts: Iterable[str],
metadatas: Optional[List[Dict[str, Any]]] = None,
**kwargs: Any,
) -> List:
) -> List[str]:
"""Run more texts through the embeddings and add to the vectorstore.
Args:
Expand Down Expand Up @@ -174,7 +174,7 @@ def add_texts(
size = 0
if texts_batch:
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:
if not texts:
Expand Down Expand Up @@ -410,7 +410,7 @@ def delete(self, ids: Optional[List[str]] = None, **kwargs: Any) -> Optional[boo
"""
search_params: dict[str, Any] = {}
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

Expand Down

0 comments on commit 26cee2e

Please sign in to comment.