Skip to content

Commit 1dd00c1

Browse files
committed
Lint
1 parent 8c33f09 commit 1dd00c1

File tree

5 files changed

+10
-109
lines changed

5 files changed

+10
-109
lines changed

libs/langchain-mongodb/langchain_mongodb/docstores.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,13 @@ def mset(
9999
batch_size: Number of documents to insert at a time.
100100
Tuning this may help with performance and sidestep MongoDB limits.
101101
"""
102-
keys, docs = zip(*key_value_pairs)
102+
keys, docs = zip(*key_value_pairs, strict=False)
103103
n_docs = len(docs)
104104
start = 0
105105
for end in range(batch_size, n_docs + batch_size, batch_size):
106106
texts, metadatas = zip(
107-
*[(doc.page_content, doc.metadata) for doc in docs[start:end]]
107+
*[(doc.page_content, doc.metadata) for doc in docs[start:end]],
108+
strict=False,
108109
)
109110
self.insert_many(texts=texts, metadatas=metadatas, ids=keys[start:end]) # type: ignore
110111
start = end
@@ -149,6 +150,7 @@ def insert_many(
149150
in the batch that do not have conflicting _ids will still be inserted.
150151
"""
151152
to_insert = [
152-
{"_id": i, self._text_key: t, **m} for i, t, m in zip(ids, texts, metadatas)
153+
{"_id": i, self._text_key: t, **m}
154+
for i, t, m in zip(ids, texts, metadatas, strict=False)
153155
]
154156
self.collection.insert_many(to_insert) # type: ignore

libs/langchain-mongodb/langchain_mongodb/index.py

Lines changed: 2 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

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

77
from pymongo.collection import Collection
8+
from pymongo.operations import SearchIndexModel
89

910
# Don't break imports for modules that expect these functions
1011
# to be in this module.
@@ -40,60 +41,6 @@ def _vector_search_index_definition(
4041
return definition
4142

4243

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

12370

124-
def update_vector_search_index(
125-
collection: Collection,
126-
index_name: str,
127-
dimensions: int,
128-
path: str,
129-
similarity: str,
130-
filters: Optional[List[str]] = None,
131-
*,
132-
wait_until_complete: Optional[float] = None,
133-
**kwargs: Any,
134-
) -> None:
135-
"""Update a search index.
136-
137-
Replace the existing index definition with the provided definition.
138-
139-
Args:
140-
collection (Collection): MongoDB Collection
141-
index_name (str): Name of Index
142-
dimensions (int): Number of dimensions in embedding
143-
path (str): field with vector embedding
144-
similarity (str): The similarity score used for the index.
145-
filters (List[str]): Fields/paths to index to allow filtering in $vectorSearch
146-
wait_until_complete (Optional[float]): If provided, number of seconds to wait
147-
until search index is ready.
148-
kwargs: Keyword arguments supplying any additional options to SearchIndexModel.
149-
"""
150-
logger.info(
151-
"Updating Search Index %s from Collection: %s", index_name, collection.name
152-
)
153-
collection.update_search_index(
154-
name=index_name,
155-
definition=_vector_search_index_definition(
156-
dimensions=dimensions,
157-
path=path,
158-
similarity=similarity,
159-
filters=filters,
160-
**kwargs,
161-
),
162-
)
163-
if wait_until_complete:
164-
_wait_for_predicate(
165-
predicate=lambda: _is_index_ready(collection, index_name),
166-
err=f"Index {index_name} update did not complete in {wait_until_complete}!",
167-
timeout=wait_until_complete,
168-
)
169-
logger.info("Update succeeded")
170-
171-
17271
def _is_index_ready(collection: Collection, index_name: str) -> bool:
17372
"""Check for the index name in the list of available search indexes to see if the
17473
specified index is of status READY

libs/langchain-mongodb/langchain_mongodb/indexes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def update(
8585
if len(keys) != len(group_ids):
8686
raise ValueError("Number of keys does not match number of group_ids")
8787

88-
for key, group_id in zip(keys, group_ids):
88+
for key, group_id in zip(keys, group_ids, strict=False):
8989
self._collection.find_one_and_update(
9090
{"namespace": self.namespace, "key": key},
9191
{"$set": {"group_id": group_id, "updated_at": self.get_time()}},

libs/langchain-mongodb/tests/integration_tests/test_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def test_mongodb_atlas_cache_matrix(
203203
for prompt_i_generations in generations
204204
]
205205

206-
for prompt_i, llm_generations_i in zip(prompts, llm_generations):
206+
for prompt_i, llm_generations_i in zip(prompts, llm_generations, strict=False):
207207
_execute_test(prompt_i, llm_string, llm_generations_i)
208208
assert llm.generate(prompts) == LLMResult(
209209
generations=llm_generations, llm_output={}

libs/langchain-mongodb/tests/unit_tests/test_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def test_mongodb_atlas_cache_matrix(
221221
for prompt_i_generations in generations
222222
]
223223

224-
for prompt_i, llm_generations_i in zip(prompts, llm_generations):
224+
for prompt_i, llm_generations_i in zip(prompts, llm_generations, strict=False):
225225
_execute_test(prompt_i, llm_string, llm_generations_i)
226226

227227
get_llm_cache()._collection._simulate_cache_aggregation_query = True # type: ignore

0 commit comments

Comments
 (0)