Skip to content

Commit 5a25f91

Browse files
authored
feat: implement Approximate Nearest Neighbor support for DDL (CREATE TABLE, CREATE VECTOR INDEX) (googleapis#124)
* fix(testing+linting): add nox lint+format directives This change introduces new nox directives: * blacken: `nox -s blacken` * format: `nox -s format` to apply formatting to files * lint: `nox -s lint` to flag linting issues * unit: to run unit tests locally which are the basis to enable scalable development and continuous testing as I prepare to bring in Approximate Nearest Neighors (ANN) functionality into this package. Also while here, fixed a typo in the README.rst file that didn't have the correct import path. * feat: add Approximate Nearest Neighbor support to distance strategies This change adds ANN distance strategies for GoogleSQL semantics. While here started unit tests to effectively test out components without having to have a running Cloud Spanner instance. Updates googleapis#94 * Ensure vector fits within limits in sample * Update ANN query names + test expectations * Pass in strategy inferred from initialization * Hook up get_documents_from_query_results * Link up __search_by_ANN to similarity_search_by_vector * Incorporate pre_filter and post_filter plus update tests * Review addressing * Simplified checking if using ANN * Reduce the amount of changes * More reductions * More reductions to ease code review * Fit with get_rows_by_similarity_search_ann * Updates from nox * Fix PostGreSQL
1 parent b10dc28 commit 5a25f91

File tree

9 files changed

+767
-55
lines changed

9 files changed

+767
-55
lines changed

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,3 +253,9 @@ Disclaimer
253253

254254
This is not an officially supported Google product.
255255

256+
257+
Limitations
258+
-----------
259+
260+
* Approximate Nearest Neighbors (ANN) strategies are only supported for the GoogleSQL dialect
261+
* ANN's `ALTER VECTOR INDEX` is not yet supported by [Google Cloud Spanner](https://cloud.google.com/spanner/docs/find-approximate-nearest-neighbors#limitations)

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import os
2020
import pathlib
2121
import shutil
22-
from pathlib import Path
2322

2423
import nox
2524

@@ -33,6 +32,7 @@
3332
"docfx",
3433
"docs",
3534
"format",
35+
"integration",
3636
"lint",
3737
"unit",
3838
]

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
google-cloud-spanner==3.49.1
2-
langchain-core==0.3.9
1+
google-cloud-spanner==3.51.0
2+
langchain-core==0.3.15
33
langchain-community==0.3.1
44
pydantic==2.9.1

src/langchain_google_spanner/graph_qa.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ def _call(
288288
inputs: Dict[str, Any],
289289
run_manager: Optional[CallbackManagerForChainRun] = None,
290290
) -> Dict[str, str]:
291+
291292
intermediate_steps: List = []
292293

293294
"""Generate gql statement, uses it to look up in db and answer question."""

src/langchain_google_spanner/graph_retriever.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def __clean_element(self, element: dict[str, Any], embedding_column: str) -> Non
225225
del element["properties"][embedding_column]
226226

227227
def __get_distance_function(
228-
self, distance_strategy=DistanceStrategy.EUCLIDEIAN
228+
self, distance_strategy=DistanceStrategy.EUCLIDEAN
229229
) -> str:
230230
"""Gets the vector distance function."""
231231
if distance_strategy == DistanceStrategy.COSINE:

0 commit comments

Comments
 (0)