Skip to content

Commit 4c1661a

Browse files
authored
feat(vertex): add additional args for vertex ai vector search (#1198)
<!-- # Thank you for contributing to LangChain-google! --> <!-- ## Checklist for PR Creation - [x] PR Title: "<type>[optional scope]: <description>" - Where type is one of: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert, release - Scope is used to specifiy the package targeted. Options are: genai, vertex, community, infra (repo-level) - [x] PR Description and Relevant issues: fix issue #1197 - [ ] Add Tests and Docs: - If adding a new integration: 1. Include a test for the integration (preferably unit tests that do not rely on network access) 2. Add an example notebook showing its use (place in the `docs/docs/integrations` directory) - [x] Lint and Test: - Run `make format`, `make lint`, and `make test` from the root of the package(s) you've modified - See contribution guidelines for more: https://github.com/langchain-ai/langchain-google/blob/main/README.md#contribute-code --> <!-- ## Additional guidelines - [ ] PR title and description are appropriate - [ ] Necessary tests and documentation have been added - [ ] Lint and tests pass successfully - [ ] The following additional guidelines are adhered to: - Optional dependencies are imported within functions - No unnecessary dependencies added to pyproject.toml files (except those required for unit tests) - PR doesn't touch more than one package - Changes are backwards compatible --> ## Description <!-- e.g. "Implement user authentication feature" --> ## Relevant issues fixes #1197 <!-- e.g. "Fixes #000" --> ## Type <!-- Select the type of Pull Request --> <!-- Keep only the necessary ones --> 🆕 New Feature 🐛 Bug Fix 🧹 Refactoring 📖 Documentation 🚄 Infrastructure ✅ Test ## Changes(optional) <!-- List of changes --> ## Testing(optional) <!-- Test procedure --> <!-- Test result --> ## Note(optional) <!-- Information about the errors fixed by PR --> <!-- Remaining issue or something --> <!-- Other information about PR -->
1 parent 9ea5b89 commit 4c1661a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

libs/vertexai/langchain_google_vertexai/vectorstores/_searcher.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def find_neighbors(
3939
List[Dict[str, Union[List[int], List[float]]]]
4040
] = None,
4141
rrf_ranking_alpha: float = 1,
42+
**kwargs: Any,
4243
) -> List[List[Dict[str, Any]]]:
4344
"""Finds the k closes neighbors of each instance of embeddings.
4445
@@ -249,6 +250,7 @@ def find_neighbors(
249250
List[Dict[str, Union[List[int], List[float]]]]
250251
] = None,
251252
rrf_ranking_alpha: float = 1,
253+
**kwargs: Any,
252254
) -> List[List[Dict[str, Any]]]:
253255
"""Finds the k closes neighbors of each instance of embeddings.
254256
@@ -304,6 +306,7 @@ def find_neighbors(
304306
num_neighbors=k,
305307
filter=filter_,
306308
numeric_filter=numeric_filter,
309+
**kwargs,
307310
)
308311

309312
return self._postprocess_response(response)

libs/vertexai/langchain_google_vertexai/vectorstores/vectorstores.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def similarity_search_with_score( # type: ignore[override]
7676
k: int = 4,
7777
filter: Optional[List[Namespace]] = None,
7878
numeric_filter: Optional[List[NumericNamespace]] = None,
79+
**kwargs: Any,
7980
) -> List[Tuple[Document, Union[float, Dict[str, float]]]]:
8081
"""Return docs most similar to query and their cosine distance from the query.
8182
@@ -103,7 +104,11 @@ def similarity_search_with_score( # type: ignore[override]
103104
embedding = self._embeddings.embed_query(query)
104105

105106
return self.similarity_search_by_vector_with_score(
106-
embedding=embedding, k=k, filter=filter, numeric_filter=numeric_filter
107+
embedding=embedding,
108+
k=k,
109+
filter=filter,
110+
numeric_filter=numeric_filter,
111+
**kwargs,
107112
)
108113

109114
def similarity_search_by_vector_with_score(
@@ -114,6 +119,7 @@ def similarity_search_by_vector_with_score(
114119
rrf_ranking_alpha: float = 1,
115120
filter: Optional[List[Namespace]] = None,
116121
numeric_filter: Optional[List[NumericNamespace]] = None,
122+
**kwargs: Any,
117123
) -> List[Tuple[Document, Union[float, Dict[str, float]]]]:
118124
"""Return docs most similar to the embedding and their cosine distance.
119125
@@ -164,6 +170,7 @@ def similarity_search_by_vector_with_score(
164170
rrf_ranking_alpha=rrf_ranking_alpha,
165171
filter_=filter,
166172
numeric_filter=numeric_filter,
173+
**kwargs,
167174
)
168175
if not neighbors_list:
169176
return []
@@ -255,7 +262,7 @@ def similarity_search(
255262
return [
256263
document
257264
for document, _ in self.similarity_search_with_score(
258-
query, k, filter, numeric_filter
265+
query, k, filter, numeric_filter, **kwargs
259266
)
260267
]
261268

0 commit comments

Comments
 (0)