Skip to content

Commit 21ac779

Browse files
committed
Replace create_vector_search_index
Remove create_vector_search_index from langchain-mongodb and import from pymongo-search-utils.
1 parent b706aa3 commit 21ac779

File tree

1 file changed

+0
-76
lines changed
  • libs/langchain-mongodb/langchain_mongodb

1 file changed

+0
-76
lines changed

libs/langchain-mongodb/langchain_mongodb/index.py

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from pymongo.collection import Collection
88
from pymongo.operations import SearchIndexModel
9-
from pymongo_search_utils import create_vector_search_index # noqa: F401
109

1110
logger = logging.getLogger(__file__)
1211

@@ -35,81 +34,6 @@ def _vector_search_index_definition(
3534
return definition
3635

3736

38-
def drop_vector_search_index(
39-
collection: Collection,
40-
index_name: str,
41-
*,
42-
wait_until_complete: Optional[float] = None,
43-
) -> None:
44-
"""Drop a created vector search index
45-
46-
Args:
47-
collection (Collection): MongoDB Collection with index to be dropped
48-
index_name (str): Name of the MongoDB index
49-
wait_until_complete (Optional[float]): If provided, number of seconds to wait
50-
until search index is ready.
51-
"""
52-
logger.info(
53-
"Dropping Search Index %s from Collection: %s", index_name, collection.name
54-
)
55-
collection.drop_search_index(index_name)
56-
if wait_until_complete:
57-
_wait_for_predicate(
58-
predicate=lambda: len(list(collection.list_search_indexes())) == 0,
59-
err=f"Index {index_name} did not drop in {wait_until_complete}!",
60-
timeout=wait_until_complete,
61-
)
62-
logger.info("Vector Search index %s.%s dropped", collection.name, index_name)
63-
64-
65-
def update_vector_search_index(
66-
collection: Collection,
67-
index_name: str,
68-
dimensions: int,
69-
path: str,
70-
similarity: str,
71-
filters: Optional[List[str]] = None,
72-
*,
73-
wait_until_complete: Optional[float] = None,
74-
**kwargs: Any,
75-
) -> None:
76-
"""Update a search index.
77-
78-
Replace the existing index definition with the provided definition.
79-
80-
Args:
81-
collection (Collection): MongoDB Collection
82-
index_name (str): Name of Index
83-
dimensions (int): Number of dimensions in embedding
84-
path (str): field with vector embedding
85-
similarity (str): The similarity score used for the index.
86-
filters (List[str]): Fields/paths to index to allow filtering in $vectorSearch
87-
wait_until_complete (Optional[float]): If provided, number of seconds to wait
88-
until search index is ready.
89-
kwargs: Keyword arguments supplying any additional options to SearchIndexModel.
90-
"""
91-
logger.info(
92-
"Updating Search Index %s from Collection: %s", index_name, collection.name
93-
)
94-
collection.update_search_index(
95-
name=index_name,
96-
definition=_vector_search_index_definition(
97-
dimensions=dimensions,
98-
path=path,
99-
similarity=similarity,
100-
filters=filters,
101-
**kwargs,
102-
),
103-
)
104-
if wait_until_complete:
105-
_wait_for_predicate(
106-
predicate=lambda: _is_index_ready(collection, index_name),
107-
err=f"Index {index_name} update did not complete in {wait_until_complete}!",
108-
timeout=wait_until_complete,
109-
)
110-
logger.info("Update succeeded")
111-
112-
11337
def _is_index_ready(collection: Collection, index_name: str) -> bool:
11438
"""Check for the index name in the list of available search indexes to see if the
11539
specified index is of status READY

0 commit comments

Comments
 (0)