Skip to content

Commit 85f5a42

Browse files
committed
Replace create_vector_search_index
Remove create_vector_search_index from langchain-mongodb and import from pymongo-search-utils.
1 parent 53bbe48 commit 85f5a42

File tree

2 files changed

+2
-55
lines changed

2 files changed

+2
-55
lines changed

libs/langchain-mongodb/langchain_mongodb/index.py

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
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
910

1011
logger = logging.getLogger(__file__)
1112

@@ -34,60 +35,6 @@ def _vector_search_index_definition(
3435
return definition
3536

3637

37-
def create_vector_search_index(
38-
collection: Collection,
39-
index_name: str,
40-
dimensions: int,
41-
path: str,
42-
similarity: str,
43-
filters: Optional[List[str]] = None,
44-
*,
45-
wait_until_complete: Optional[float] = None,
46-
**kwargs: Any,
47-
) -> None:
48-
"""Experimental Utility function to create a vector search index
49-
50-
Args:
51-
collection (Collection): MongoDB Collection
52-
index_name (str): Name of Index
53-
dimensions (int): Number of dimensions in embedding
54-
path (str): field with vector embedding
55-
similarity (str): The similarity score used for the index
56-
filters (List[str]): Fields/paths to index to allow filtering in $vectorSearch
57-
wait_until_complete (Optional[float]): If provided, number of seconds to wait
58-
until search index is ready.
59-
kwargs: Keyword arguments supplying any additional options to SearchIndexModel.
60-
"""
61-
logger.info("Creating Search Index %s on %s", index_name, collection.name)
62-
63-
if collection.name not in collection.database.list_collection_names(
64-
authorizedCollections=True
65-
):
66-
collection.database.create_collection(collection.name)
67-
68-
result = collection.create_search_index(
69-
SearchIndexModel(
70-
definition=_vector_search_index_definition(
71-
dimensions=dimensions,
72-
path=path,
73-
similarity=similarity,
74-
filters=filters,
75-
**kwargs,
76-
),
77-
name=index_name,
78-
type="vectorSearch",
79-
)
80-
)
81-
82-
if wait_until_complete:
83-
_wait_for_predicate(
84-
predicate=lambda: _is_index_ready(collection, index_name),
85-
err=f"{index_name=} did not complete in {wait_until_complete}!",
86-
timeout=wait_until_complete,
87-
)
88-
logger.info(result)
89-
90-
9138
def drop_vector_search_index(
9239
collection: Collection,
9340
index_name: str,

libs/langchain-mongodb/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ disallow_untyped_defs = true
6868

6969
[[tool.mypy.overrides]]
7070
module = ["tests.*"]
71-
disable_error_code = ["no-untyped-def", "no-untyped-call", "var-annotated"]
71+
disable_error_code = ["no-untyped-def", "no-untyped-call", "var-annotated", "import-untyped"]
7272

7373
[tool.ruff]
7474
lint.select = [

0 commit comments

Comments
 (0)