Skip to content

Commit 1392a98

Browse files
authored
Updated LangChain doc to use langchain-neo4j (#104)
1 parent ebfed2e commit 1392a98

File tree

1 file changed

+25
-50
lines changed

1 file changed

+25
-50
lines changed

modules/genai-ecosystem/pages/langchain.adoc

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ It manages templates, composes components into chains and supports monitoring an
1717

1818
The broad and deep Neo4j integration allows for vector search, cypher generation and database querying and knowledge graph construction.
1919

20-
Here is an overview of the https://python.langchain.com/docs/use_cases/graph/quickstart[Graph Integrations^].
20+
Here is an overview of the https://python.langchain.com/docs/tutorials/graph/[Graph Integrations^].
2121

2222
* https://medium.com/towards-data-science/integrating-neo4j-into-the-langchain-ecosystem-df0e988344d2[Integrating Neo4j into the LangChain Ecosystem^]
2323
@@ -66,7 +66,7 @@ embeddings = OpenAIEmbeddings()
6666
# The Neo4jVector Module will connect to Neo4j and create a vector index if needed.
6767
6868
db = Neo4jVector.from_documents(
69-
docs, OpenAIEmbeddings(), url=url, username=username, password=password
69+
docs, embeddings, url=url, username=username, password=password
7070
)
7171
7272
query = "What did the president say about Ketanji Brown Jackson"
@@ -101,8 +101,8 @@ embeddings = OpenAIEmbeddings()
101101
# The Neo4jVector Module will connect to Neo4j and create a vector index if needed.
102102
103103
db = Neo4jVector.from_documents(
104-
docs, OpenAIEmbeddings(), url=url, username=username, password=password,
105-
search_type: 'hybrid'
104+
docs, embeddings, url=url, username=username, password=password,
105+
search_type="hybrid"
106106
)
107107
108108
query = "What did the president say about Ketanji Brown Jackson"
@@ -142,12 +142,12 @@ from langchain_neo4j import Neo4jGraph
142142
graph = Neo4jGraph(url=NEO4J_URI, username=NEO4J_USERNAME, password=NEO4J_PASSWORD)
143143
144144
QUERY = """
145-
"MATCH (m:Movie)-[:IN_GENRE]->(:Genre {name:$genre})
145+
MATCH (m:Movie)-[:IN_GENRE]->(:Genre {name: $genre})
146146
RETURN m.title, m.plot
147-
ORDER BY m.imdbRating DESC LIMIT 5"
147+
ORDER BY m.imdbRating DESC LIMIT 5
148148
"""
149149
150-
graph.query(QUERY, genre="action")
150+
graph.query(QUERY, params={"genre": "action"})
151151
----
152152

153153
=== CypherQAChain
@@ -168,20 +168,21 @@ graph = Neo4jGraph(url=NEO4J_URI, username=NEO4J_USERNAME, password=NEO4J_PASSWO
168168
169169
# Insert some movie data
170170
graph.query(
171-
"""
172-
MERGE (m:Movie {title:"Top Gun"})
171+
"""
172+
MERGE (m:Movie {title:'Top Gun'})
173173
WITH m
174-
UNWIND ["Tom Cruise", "Val Kilmer", "Anthony Edwards", "Meg Ryan"] AS actor
174+
UNWIND ['Tom Cruise', 'Val Kilmer', 'Anthony Edwards', 'Meg Ryan'] AS actor
175175
MERGE (a:Actor {name:actor})
176176
MERGE (a)-[:ACTED_IN]->(m)
177177
"""
178178
)
179179
180180
chain = GraphCypherQAChain.from_llm(
181-
ChatOpenAI(temperature=0), graph=graph, verbose=True
181+
ChatOpenAI(temperature=0), graph=graph, verbose=True,
182+
allow_dangerous_requests=True
182183
)
183184
184-
chain.run("Who played in Top Gun?")
185+
chain.run("Who acted in Top Gun?")
185186
----
186187

187188
=== Advanced RAG Strategies
@@ -196,8 +197,6 @@ These are also available as LangChain Templates.
196197

197198
* https://blog.langchain.dev/implementing-advanced-retrieval-rag-strategies-with-neo4j/[Implementing Advanced Retrieval RAG Strategies with Neo4j^]
198199

199-
* https://python.langchain.com/docs/templates/neo4j-advanced-rag
200-
201200
[source,shell]
202201
----
203202
pip install -U "langchain-cli[serve]"
@@ -228,33 +227,6 @@ langchain serve
228227

229228
image::https://lh7-us.googleusercontent.com/jfDNiPa5ccefX6h0HiVzJbqnlgAZgfPda90truHSfbwSs3JkfxZ-xbA9mZE8y2fNf_3n5cgVhbdhN0ryuMoK2JNbMgTe1OLJMA6CQRhWBxzdKRLVurUFDndT7ki4vMh-cdv3SAn040HTpab9XkzGj5Q[]
230229

231-
=== LangChain Templates
232-
233-
https://blog.langchain.dev/langchain-templates/[Langchain Templates^] are a set of preconfigured chains and components that can be used to build GenAI workflows and applications.
234-
You can test them interactively on the LangChain Playground and run them with https://github.com/langchain-ai/langserve[LangServe^] to run as REST APIs, they also integrate with [LangSmith] for monitoring and observability.
235-
236-
By creating an application from templates, their source code is added to your application and you can modify them to fit your needs.
237-
238-
==== List of Templates
239-
240-
This https://python.langchain.com/docs/templates/neo4j-cypher[Cypher template] allows you to interact with a Neo4j graph database in natural language, using an OpenAI LLM.
241-
242-
It transforms a natural language question into a Cypher query (used to fetch data from Neo4j databases), executes the query, and provides a natural language response based on the query results.
243-
244-
The https://python.langchain.com/docs/templates/neo4j-cypher-ft[Cypher-FT Template^] additionally utilizes a full-text index for efficient mapping of text values to database entries, thereby enhancing the generation of accurate Cypher statements.
245-
246-
The https://python.langchain.com/docs/templates/neo4j-cypher-memory[Cypher Memory Template^] also features a conversational memory module that stores the dialogue history in the Neo4j graph database. The conversation memory is uniquely maintained for each user session, ensuring personalized interactions.
247-
248-
The https://python.langchain.com/docs/templates/neo4j-generation[Neo4j generation Template^] pairs LLM-based knowledge graph extraction using OpenAI functions, with Neo4j AuraDB, a fully managed cloud graph database.
249-
250-
This https://python.langchain.com/docs/templates/neo4j-vector-memory[Neo4j Vector Memory Template^] allows you to integrate an LLM with a vector-based retrieval system using Neo4j as the vector store. Additionally, it uses the graph capabilities of the Neo4j database to store and retrieve the dialogue history of a specific user's session. Having the dialogue history stored as a graph allows for seamless conversational flows but also gives you the ability to analyze user behavior and text chunk retrieval through graph analytics.
251-
252-
The https://python.langchain.com/docs/templates/neo4j-parent[Parent-Child Retriever Template^] allows you to balance precise embeddings and context retention by splitting documents into smaller chunks and retrieving their original or larger text information.
253-
254-
Using a Neo4j vector index, the package queries child nodes using vector similarity search and retrieves the corresponding parent's text.
255-
256-
The https://python.langchain.com/docs/templates/neo4j-semantic-layer[Neo4j Semantic Layer Template^] is designed to implement an agent capable of interacting with a graph database like Neo4j through a semantic layer using OpenAI function calling. The semantic layer equips the agent with a suite of robust tools, allowing it to interact with the graph databas based on the user's intent.
257-
258230
=== Semantic Layer
259231

260232
A semantic layer on top of a (graph) database doesn't rely on automatic query generation but offers a number of APIs and tools to give the LLM access to the database and it's structures.
@@ -282,14 +254,14 @@ You can index embeddings for and link questions and answers back to the retrieve
282254

283255
Creating a Knowledge Graph from unstructured data like PDF documents used to be a complex and time-consuming task that required training and using dedicated, large NLP models.
284256

285-
The https://python.langchain.com/docs/use_cases/graph/constructing[Graph Transformers^] are tools that allows you to extract structured data from unstructured documents and transform it into a Knowledge Graph.
257+
The https://python.langchain.com/v0.1/docs/use_cases/graph/constructing[Graph Transformers^] are tools that allows you to extract structured data from unstructured documents and transform it into a Knowledge Graph.
286258

287259
NOTE: You can see a practical application, code and demo for extracting knowledge graphs from PDFs, YouTube transcripts, wikipedia articles and more with the xref:llm-graph-builder.adoc[LLM Graph Builder].
288260

289261
image::
290262

291-
* https://python.langchain.com/docs/use_cases/graph/integrations/diffbot_graphtransformer[Diffbot Graph Transformer^]
292-
* https://python.langchain.com/docs/use_cases/graph/constructing#llm-graph-transformer[LLM Graph Transformer^]
263+
* https://python.langchain.com/docs/integrations/graphs/diffbot/[Diffbot Graph Transformer^]
264+
* https://python.langchain.com/v0.1/docs/use_cases/graph/constructing/#llm-graph-transformer[LLM Graph Transformer^]
293265

294266
* https://neo4j.com/developer-blog/knowledge-graph-based-chatbot-with-gpt-3-and-neo4j/[Knowledge Graph-based Chatbot with GPT-3 and Neo4j^]
295267
* https://blog.langchain.dev/constructing-knowledge-graphs-from-text-using-openai-functions/[Constructing Knowledge Graphs from Text using OpenAI Functions^]
@@ -299,13 +271,13 @@ image::
299271
== Documentation
300272

301273
* https://python.langchain.com/docs/integrations/providers/neo4j/[Neo4j Integrations^]
302-
* https://python.langchain.com/docs/use_cases/graph/graph_cypher_qa[Graph Cypher QA Chain^]
274+
* https://python.langchain.com/docs/tutorials/graph/#chain[Graph Cypher QA Chain^]
303275
* https://python.langchain.com/docs/integrations/vectorstores/neo4jvector[Neo4j Vector^]
304-
* https://python.langchain.com/docs/use_cases/graph/constructing[Graph Transformers^]
276+
* https://python.langchain.com/v0.1/docs/use_cases/graph/constructing[Graph Transformers^]
305277

306278
== Starter Kit
307279

308-
This https://github.com/neo4j-examples/langchain-starter-kit/blob/main/app/vector_chain.py[starter-kit] demonstrates how to run a FastAPI server using LangChain to answer queries on data stored in a Neo4j instance. The single endpoint can be used to retrieve answers using either a https://python.langchain.com/v0.1/docs/integrations/vectorstores/neo4jvector/[Vector index chain], https://python.langchain.com/v0.1/docs/integrations/graphs/neo4j_cypher/[GraphCypherQA Chain], or a composite answer of both. The https://github.com/neo4j-examples/langchain-starter-kit/tree/langserve[langserve] branch contains an example of the same service, using https://python.langchain.com/v0.1/docs/langserve/[LangServe]
280+
This https://github.com/neo4j-examples/langchain-starter-kit/blob/main/app/vector_chain.py[starter-kit] demonstrates how to run a FastAPI server using LangChain to answer queries on data stored in a Neo4j instance. The single endpoint can be used to retrieve answers using either a https://python.langchain.com/docs/integrations/vectorstores/neo4jvector/[Vector index chain], https://python.langchain.com/docs/integrations/graphs/neo4j_cypher/[GraphCypherQA Chain], or a composite answer of both. The https://github.com/neo4j-examples/langchain-starter-kit/tree/langserve[langserve] branch contains an example of the same service, using https://python.langchain.com/v0.1/docs/langserve/[LangServe]
309281

310282
See this https://neo4j.com/developer-blog/langchain-neo4j-starter-kit/[Developer Blog Article] for additional details and instructions on working with the Starter Kit.
311283

@@ -314,10 +286,13 @@ See this https://neo4j.com/developer-blog/langchain-neo4j-starter-kit/[Developer
314286
|===
315287
| icon:user[] Authors | https://github.com/tomasonjo[Tomaz Bratanic^]
316288
| icon:comments[] Community Support | https://community.neo4j.com/[Neo4j Online Community^]
317-
| icon:github[] Data Repository | https://github.com/langchain-ai/langchain[GitHub]
318-
| icon:github[] Issues | https://github.com/langchain-ai/langchain/issues
289+
| icon:github[] LangChain Repository | https://github.com/langchain-ai/langchain[GitHub]
290+
| icon:github[] LangChain Issues | https://github.com/langchain-ai/langchain/issues[Issues]
291+
| icon:github[] LangChain Neo4j Repository | https://github.com/langchain-ai/langchain-neo4j[GitHub]
292+
| icon:book[] LangChain Neo4j API Docs | https://python.langchain.com/api_reference/neo4j/index.html[API Docs]
293+
| icon:book[] LangChain Neo4j Issues | https://github.com/langchain-ai/langchain-neo4j/issues[Issues]
319294
| icon:book[] Documentation | https://python.langchain.com/docs/integrations/providers/neo4j/[Neo4j Integrations^]
320-
| icon:book[] Documentation | https://python.langchain.com/docs/use_cases/graph/quickstart[Graph Overview Docs^]
295+
| icon:book[] Documentation | https://python.langchain.com/docs/tutorials/graph[Graph Overview Docs^]
321296
| icon:github[] Starter Kit |https://github.com/neo4j-examples/langchain-starter-kit[LangChain Starter Kit^]
322297
| icon:code[] Juypter | https://github.com/tomasonjo/blogs/tree/master/llm[Jupyter Notebooks^]
323298
|===

0 commit comments

Comments
 (0)