Skip to content

SpannerGraphVectorContextRetriever doesn't support Approximate Nearest Neighbor search #163

Description

@ArpanMajumdar

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 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":

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.

    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.

GRAPH TestGraph
MATCH (node:Node1)
WHERE node.embedding is not NULL
ORDER BY APPROX_DOT_PRODUCT(node.embedding, ARRAY<FLOAT32>[
      -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!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

api: spannerIssues related to the googleapis/langchain-google-spanner-python API.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions