googleapis / googleapis/langchain-google-spanner-python

SpannerGraphVectorContextRetriever doesn't support Approximate Nearest Neighbor search

Open
#163 0 comments 0 reactions 1 assignee Claimed by @gauravpurohit06 View on GitHub
api: spanner
Dominant language
Python
Stars
44
Forks
24
PR merge metrics
No merged PRs in 30d

Description

Thanks for stopping by to let us know something could be better!

**PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response.

Please run down the following list and make sure you've tried the usual "quick fixes":

- Search the issues already opened: https://github.com/googleapis/langchain-google-spanner-python/issues
- Search StackOverflow: https://stackoverflow.com/questions/tagged/google-cloud-platform+python

If you are still having issues, please be sure to include as much information as possible:

#### Environment details

- OS type and version: MacOS Darwin Kernel Version 23.6.0 arm64
- Python version: 3.12.9
- pip version: pip 25.0.1
- `langchain-google-spanner` version: 0.8.1

#### Steps to reproduce

I'm unable to use APPROX_DOT_PRODUCT metric for vector search in the `SpannerGraphVectorContextRetriever`. Upon checking the implementation, I found that the `__get_distance_function` only supports COSINE and EUCLIDEAN distance.
```python
def __get_distance_function(
self, distance_strategy=DistanceStrategy.EUCLIDEAN
) -> str:
"""Gets the vector distance function."""
if distance_strategy == DistanceStrategy.COSINE:
return "COSINE_DISTANCE"

return "EUCLIDEAN_DISTANCE"
```

Here is an example Spanner Graph query I'm trying to create.
```sql
GRAPH TestGraph
MATCH (node:Node1)
WHERE node.embedding is not NULL
ORDER BY APPROX_DOT_PRODUCT(node.embedding, ARRAY[
-0.036149498,
0.07207133,
-0.020961108,
-0.005176733,
0.047590617,
0.006568967,
-0.047031555,
0.04741984
],
OPTIONS => JSON '{"num_leaves_to_search": 5}') DESC
LIMIT 5
RETURN node.col1, node.col2;
```
Can you help me in how can I create a Spanner Graph query which uses Approximate Nearest Neighbors vector index.

Thanks!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.