Skip to content

Commit c07c9b2

Browse files
authored
INTPYTHON-838 Allow additional arguments to vector_search_index_definition (#267)
This pull request adds support for passing custom vector index options throughout the vector search index creation and update workflows in the MongoDB integration. This enhancement allows users to specify additional parameters for vector index configuration, increasing flexibility and control over index behavior. Enhancements to vector index configuration: * Added a new `vector_index_options` parameter to the `_vector_search_index_definition`, `create_vector_search_index`, and `update_vector_search_index` functions in `index.py`, enabling custom options to be merged into the index definition. [[1]](diffhunk://#diff-ded4d757aa6ceaa72da4d733902d2754b87d8e30294ac133b52d93345a2a6492R18-R29) [[2]](diffhunk://#diff-ded4d757aa6ceaa72da4d733902d2754b87d8e30294ac133b52d93345a2a6492R47) [[3]](diffhunk://#diff-ded4d757aa6ceaa72da4d733902d2754b87d8e30294ac133b52d93345a2a6492R79) [[4]](diffhunk://#diff-ded4d757aa6ceaa72da4d733902d2754b87d8e30294ac133b52d93345a2a6492R130) [[5]](diffhunk://#diff-ded4d757aa6ceaa72da4d733902d2754b87d8e30294ac133b52d93345a2a6492R160) * Updated the `MongoDBAtlasVectorSearch` class in `vectorstores.py` to accept and forward the `vector_index_options` parameter during initialization and index creation, ensuring consistent propagation of custom options. [[1]](diffhunk://#diff-6dc2a6cf887e0d19be789087d31e249730d5f33112e0f784defb71eb92ad2a4eR215) [[2]](diffhunk://#diff-6dc2a6cf887e0d19be789087d31e249730d5f33112e0f784defb71eb92ad2a4eR260) [[3]](diffhunk://#diff-6dc2a6cf887e0d19be789087d31e249730d5f33112e0f784defb71eb92ad2a4eR846) [[4]](diffhunk://#diff-6dc2a6cf887e0d19be789087d31e249730d5f33112e0f784defb71eb92ad2a4eR885)[Issue Key](https://jira.mongodb.org/browse/{ISSUE_KEY})
1 parent cce6df2 commit c07c9b2

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

libs/langchain-mongodb/langchain_mongodb/index.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@ def _vector_search_index_definition(
2020
path: str,
2121
similarity: str,
2222
filters: Optional[List[str]] = None,
23+
vector_index_options: dict | None = None,
2324
**kwargs: Any,
2425
) -> Dict[str, Any]:
2526
# https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-type/
27+
vector_index_options = vector_index_options or {}
2628
fields = [
2729
{
2830
"numDimensions": dimensions,
2931
"path": path,
3032
"similarity": similarity,
3133
"type": "vector",
34+
**vector_index_options,
3235
},
3336
]
3437
if filters:

libs/langchain-mongodb/langchain_mongodb/vectorstores.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ def __init__(
213213
dimensions: int = -1,
214214
auto_create_index: bool | None = None,
215215
auto_index_timeout: int = 15,
216+
vector_index_options: dict | None = None,
216217
**kwargs: Any,
217218
):
218219
"""
@@ -257,6 +258,7 @@ def __init__(
257258
path=embedding_key,
258259
similarity=relevance_score_fn,
259260
wait_until_complete=auto_index_timeout,
261+
vector_index_options=vector_index_options,
260262
)
261263

262264
@property
@@ -829,6 +831,7 @@ def create_vector_search_index(
829831
filters: Optional[List[str]] = None,
830832
update: bool = False,
831833
wait_until_complete: Optional[float] = None,
834+
vector_index_options: dict | None = None,
832835
**kwargs: Any,
833836
) -> None:
834837
"""Creates a MongoDB Atlas vectorSearch index for the VectorStore
@@ -867,6 +870,7 @@ def create_vector_search_index(
867870
path=self._embedding_key,
868871
similarity=self._relevance_score_fn,
869872
filters=filters or [],
873+
vector_index_options=vector_index_options,
870874
wait_until_complete=wait_until_complete,
871875
**kwargs,
872876
) # type: ignore [operator]

0 commit comments

Comments
 (0)