Skip to content

Commit e83fc9d

Browse files
committed
Replace create_fulltext_search_index
1 parent 974a39c commit e83fc9d

File tree

1 file changed

+2
-49
lines changed
  • libs/langchain-mongodb/langchain_mongodb

1 file changed

+2
-49
lines changed

libs/langchain-mongodb/langchain_mongodb/index.py

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
import logging
44
from time import monotonic, sleep
5-
from typing import Any, Callable, Dict, List, Optional, Union
5+
from typing import Any, Callable, Dict, List, Optional
66

77
from pymongo.collection import Collection
8-
from pymongo.operations import SearchIndexModel
98
from pymongo_search_utils import (
9+
create_fulltext_search_index, # noqa: F401
1010
create_vector_search_index, # noqa: F401
1111
drop_vector_search_index, # noqa: F401
1212
update_vector_search_index, # noqa: F401
@@ -75,50 +75,3 @@ def _wait_for_predicate(
7575
if monotonic() - start > timeout:
7676
raise TimeoutError(err)
7777
sleep(interval)
78-
79-
80-
def create_fulltext_search_index(
81-
collection: Collection,
82-
index_name: str,
83-
field: Union[str, List[str]],
84-
*,
85-
wait_until_complete: Optional[float] = None,
86-
**kwargs: Any,
87-
) -> None:
88-
"""Experimental Utility function to create an Atlas Search index
89-
90-
Args:
91-
collection (Collection): MongoDB Collection
92-
index_name (str): Name of Index
93-
field (str): Field to index
94-
wait_until_complete (Optional[float]): If provided, number of seconds to wait
95-
until search index is ready
96-
kwargs: Keyword arguments supplying any additional options to SearchIndexModel.
97-
"""
98-
logger.info("Creating Search Index %s on %s", index_name, collection.name)
99-
100-
if collection.name not in collection.database.list_collection_names(
101-
authorizedCollections=True
102-
):
103-
collection.database.create_collection(collection.name)
104-
105-
if isinstance(field, str):
106-
fields_definition = {field: [{"type": "string"}]}
107-
else:
108-
fields_definition = {f: [{"type": "string"}] for f in field}
109-
definition = {"mappings": {"dynamic": False, "fields": fields_definition}}
110-
result = collection.create_search_index(
111-
SearchIndexModel(
112-
definition=definition,
113-
name=index_name,
114-
type="search",
115-
**kwargs,
116-
)
117-
)
118-
if wait_until_complete:
119-
_wait_for_predicate(
120-
predicate=lambda: _is_index_ready(collection, index_name),
121-
err=f"{index_name=} did not complete in {wait_until_complete}!",
122-
timeout=wait_until_complete,
123-
)
124-
logger.info(result)

0 commit comments

Comments
 (0)