Skip to content

Commit 98c2f8f

Browse files
feat(graph): add Spanner Graph support to LangChain GraphStore interface (googleapis#104)
* feat(graph): add Spanner Graph support to LangChain GraphStore interface 1) Add SpannerGraphStore implementation of GraphStore; 2) Add an integration test; 3) Add a notebook to demonstrate the usage; 4) Misc updates: requirements, __init__ * Allow more flexible input that can generated by LLMs 1) same edge label between different types of nodes E.g. Company FOCUS_ON Product Company FOCUS_ON Technology 2) the same doc contains multiple nodes/edges with the same key fields. E.g. Merge Company(id='Google', properties={'p1':'a1', 'p3':'a3'}), Company(id='Google', properties={'p2':'a2', 'p3':'a4'}) into Company(id='Google', properties={'p1':'a1', 'p2':'a2', 'p3':'a4'}) This is due to Spanner DML doesn't support updating the same row twice in the same DML. We could also separate each node/edge into a separate DML which can be very slow. * style: formatting * style: formatting * Address various review feedbacks 1) Fix style of python notebook; 2) GraphStore: - improve a corner case by avoiding full set iteration; - add some null checking; - move utilities around. * Format the notebook * Fix linter error * Fix type annotation * Use batch table insertion API instead of transaction DML API * Minor fixes & cleanups: colab, requirements, tests, schema corner cases --------- Co-authored-by: Gaurav Purohit <[email protected]> Co-authored-by: gauravpurohit <[email protected]>
1 parent cb9ba08 commit 98c2f8f

File tree

6 files changed

+2377
-0
lines changed

6 files changed

+2377
-0
lines changed

README.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,27 @@ See the full `Chat Message History`_ tutorial.
131131

132132
.. _`Chat Message History`: https://github.com/googleapis/langchain-google-spanner-python/blob/main/docs/chat_message_history.ipynb
133133

134+
Spanner Graph Store Usage
135+
~~~~~~~~~~~~~~~~~~~~~~~~~~
136+
137+
Use ``SpannerGraphStore`` to store nodes and edges extracted from documents.
138+
139+
.. code:: python
140+
141+
from langchain_google_spanner import SpannerGraphStore
142+
143+
144+
graph = SpannerGraphStore(
145+
instance_id="my-instance",
146+
database_id="my-database",
147+
graph_name="my_graph",
148+
)
149+
150+
See the full `Spanner Graph Store`_ tutorial.
151+
152+
.. _`Spanner Graph Store`: https://github.com/googleapis/langchain-google-spanner-python/blob/main/docs/graph_store.ipynb
153+
154+
134155
Contributions
135156
~~~~~~~~~~~~~
136157

0 commit comments

Comments
 (0)