Skip to content

Commit

Permalink
Few minor changes to the SpannerGraphNodeVectorRetriever
Browse files Browse the repository at this point in the history
  • Loading branch information
Amarnath Mullick committed Dec 16, 2024
1 parent 1daf9e6 commit c46ee65
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/langchain_google_spanner/graph_retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,12 @@ class SpannerGraphNodeVectorRetriever(BaseRetriever):
embeddings_column: str = "embedding"
"""The name of the column that stores embedding"""
query_parameters: QueryParameters = QueryParameters()
k: int = 10
"""Number of top results to return"""
top_k: int = 3
"""Number of vector similarity matches to return"""
graph_expansion_query: str = ""
"""GQL query to expand the returned context"""
k: int = 10
"""Number of graph results to return"""

@classmethod
def from_params(
Expand Down Expand Up @@ -278,9 +280,10 @@ def _get_relevant_documents(
VECTOR_QUERY = """
GRAPH {graph_name}
MATCH ({node_var}:{label_expr})
WHERE {node_var}.{embeddings_column} IS NOT NULL
ORDER BY {distance_fn}({node_var}.{embeddings_column},
ARRAY[{query_embeddings}])
LIMIT {k}
LIMIT {top_k}
"""
gql_query = VECTOR_QUERY.format(
graph_name=graph_name,
Expand All @@ -289,7 +292,7 @@ def _get_relevant_documents(
embeddings_column=self.embeddings_column,
distance_fn=distance_fn,
query_embeddings=",".join(map(str, query_embeddings)),
k=self.k,
top_k=self.top_k,
)

if self.return_properties_list:
Expand Down

0 comments on commit c46ee65

Please sign in to comment.