-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(graph): Add Custom Retrievers for Spanner Graph RAG. #122
Merged
Merged
Changes from 29 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
80b6f19
Add Spanner Graph QA Chain
d8e6640
Formatted notebook. Added copyright message to prompts file.
7a27522
Add missing imports for random graph name
e0bbdf1
Make input table name randomized in integration tests to avoid name c…
7f578bc
Provide timeout to graph cleanup
3650d89
Make default timeout of 300 secs for ddl application
63b3508
Increase timeout of integration test
b9f718c
Change integration test timeout
95768fc
Minor formatting fixes
638cdeb
Make the ddl operations test fixture scoped for the module
88aa4c1
Addressed review comments
a211728
Addressed a few other review comments.
80338fc
Remove unused function
c8799ea
fix type check errors
0d358aa
Addressed review comments
340eadc
Addressed review comments
1439f04
Clear default project id from notebook
449ec35
Merge branch 'main' into graphqachain
amullick-git 06d0489
Add import statement for SpanerGraphQAChain to notebook
81a35e3
Merge branch 'graphqachain' of https://github.com/amullick-git/langch…
a086ff6
Add retrievers for Spanner Graph RAG
1ae9fec
Add licence headers
704ed32
Fix DATABASE name key
11f674e
Fix lint error on import ordering
1daf9e6
Fix lint errors
c46ee65
Few minor changes to the SpannerGraphNodeVectorRetriever
67d9c5e
Fix lint error
b3e4e3c
Add an option to expand context graph by hops
f8db780
Fix lint error
c0fdd69
Addressed review comments
17dba7f
Remove expansion query options
ebe0b86
Add backticks to property names
eb30c87
Change copyright year
441fa51
Address review comments
91421fa
Rename the retrievers. Merge the semantic retriever with the gql retr…
3d9b6f6
Fixed lint errors
dc4f993
Merge branch 'main' into graphqachain
amullick-git 2a3b63e
Change vertex ai versionto latest
d6e3173
Merge branch 'graphqachain' of https://github.com/amullick-git/langch…
577f511
Fix lint errors
82d427a
Add documentation. Fixes the case where expands_by_hops is 0
685d1f1
Add unit test for expand_by_hops=0
1aeb21c
Fix formatting for documentation
905cf65
Addressed review comments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
|
||
from __future__ import annotations | ||
|
||
import re | ||
from typing import Any, Dict, List, Optional | ||
|
||
from langchain.chains.base import Chain | ||
|
@@ -28,6 +27,7 @@ | |
|
||
from langchain_google_spanner.graph_store import SpannerGraphStore | ||
|
||
from .graph_utils import extract_gql, fix_gql_syntax | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will have to note this as a breaking change. I can add that manually to the change log when releasing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ack. Thank you for point this out. |
||
from .prompts import ( | ||
DEFAULT_GQL_FIX_TEMPLATE, | ||
DEFAULT_GQL_TEMPLATE, | ||
|
@@ -71,50 +71,6 @@ class VerifyGqlOutput(BaseModel): | |
INTERMEDIATE_STEPS_KEY = "intermediate_steps" | ||
|
||
|
||
def fix_gql_syntax(query: str) -> str: | ||
"""Fixes the syntax of a GQL query. | ||
Example 1: | ||
Input: | ||
MATCH (p:paper {id: 0})-[c:cites*8]->(p2:paper) | ||
Output: | ||
MATCH (p:paper {id: 0})-[c:cites]->{8}(p2:paper) | ||
Example 2: | ||
Input: | ||
MATCH (p:paper {id: 0})-[c:cites*1..8]->(p2:paper) | ||
Output: | ||
MATCH (p:paper {id: 0})-[c:cites]->{1:8}(p2:paper) | ||
|
||
Args: | ||
query: The input GQL query. | ||
|
||
Returns: | ||
Possibly modified GQL query. | ||
""" | ||
|
||
query = re.sub(r"-\[(.*?):(\w+)\*(\d+)\.\.(\d+)\]->", r"-[\1:\2]->{\3,\4}", query) | ||
query = re.sub(r"-\[(.*?):(\w+)\*(\d+)\]->", r"-[\1:\2]->{\3}", query) | ||
query = re.sub(r"<-\[(.*?):(\w+)\*(\d+)\.\.(\d+)\]-", r"<-[\1:\2]-{\3,\4}", query) | ||
query = re.sub(r"<-\[(.*?):(\w+)\*(\d+)\]-", r"<-[\1:\2]-{\3}", query) | ||
query = re.sub(r"-\[(.*?):(\w+)\*(\d+)\.\.(\d+)\]-", r"-[\1:\2]-{\3,\4}", query) | ||
query = re.sub(r"-\[(.*?):(\w+)\*(\d+)\]-", r"-[\1:\2]-{\3}", query) | ||
return query | ||
|
||
|
||
def extract_gql(text: str) -> str: | ||
"""Extract GQL query from a text. | ||
|
||
Args: | ||
text: Text to extract GQL query from. | ||
|
||
Returns: | ||
GQL query extracted from the text. | ||
""" | ||
pattern = r"```(.*?)```" | ||
matches = re.findall(pattern, text, re.DOTALL) | ||
query = matches[0] if matches else text | ||
return fix_gql_syntax(query) | ||
|
||
|
||
class SpannerGraphQAChain(Chain): | ||
"""Chain for question-answering against a Spanner Graph database by | ||
generating GQL statements from natural language questions. | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I like to use "my-project-id" instead of a empty value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done