mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-20 19:41:23 +00:00
Update neo4j template readmes (#12540)
This commit is contained in:
parent
b2138508cb
commit
8e88ba16a8
@ -1,9 +1,22 @@
|
||||
# Neo4j Knowledge Graph: Enhanced mapping from text to database using a full-text index
|
||||
|
||||
This template allows you to chat with Neo4j graph database in natural language, using an OpenAI LLM.
|
||||
Its primary purpose is to convert a natural language question into a Cypher query (which is used to query Neo4j databases),
|
||||
execute the query, and then provide a natural language response based on the query's results.
|
||||
The addition of the full-text index ensures efficient mapping of values from text to database for more precise Cypher statement generation.
|
||||
In this example, full-text index is used to map names of people and movies from the user's query with corresponding database entries.
|
||||
|
||||
## Set up Environment
|
||||
## Neo4j database
|
||||
|
||||
There are a number of ways to set up a Neo4j database.
|
||||
|
||||
### Neo4j Aura
|
||||
|
||||
Neo4j AuraDB is a fully managed cloud graph database service.
|
||||
Create a free instance on [Neo4j Aura](https://neo4j.com/cloud/platform/aura-graph-database?utm_source=langchain&utm_content=langserve).
|
||||
When you initiate a free database instance, you'll receive credentials to access the database.
|
||||
|
||||
## Environment variables
|
||||
|
||||
You need to define the following environment variables
|
||||
|
||||
@ -14,9 +27,16 @@ NEO4J_USERNAME=<YOUR_NEO4J_USERNAME>
|
||||
NEO4J_PASSWORD=<YOUR_NEO4J_PASSWORD>
|
||||
```
|
||||
|
||||
## Populating with data
|
||||
|
||||
If you want to populate the DB with some example data, you can run `python ingest.py`.
|
||||
This script will populate the database with sample movie data.
|
||||
Additionally, it will create an full-text index named `entity`, which is used to
|
||||
map person and movies from user input to database values for precise Cypher statement generation.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
# from inside your LangServe instance
|
||||
poe add neo4j-cypher
|
||||
poe add neo4j-cypher-ft
|
||||
```
|
||||
|
@ -1,8 +1,20 @@
|
||||
# Neo4j Knowledge Graph with OpenAI LLMs
|
||||
|
||||
This template allows you to chat with Neo4j graph database in natural language, using an OpenAI LLM.
|
||||
Its primary purpose is to convert a natural language question into a Cypher query (which is used to query Neo4j databases),
|
||||
execute the query, and then provide a natural language response based on the query's results.
|
||||
|
||||
## Set up Environment
|
||||
## Neo4j database
|
||||
|
||||
There are a number of ways to set up a Neo4j database.
|
||||
|
||||
### Neo4j Aura
|
||||
|
||||
Neo4j AuraDB is a fully managed cloud graph database service.
|
||||
Create a free instance on [Neo4j Aura](https://neo4j.com/cloud/platform/aura-graph-database?utm_source=langchain&utm_content=langserve).
|
||||
When you initiate a free database instance, you'll receive credentials to access the database.
|
||||
|
||||
## Environment variables
|
||||
|
||||
You need to define the following environment variables
|
||||
|
||||
@ -13,6 +25,11 @@ NEO4J_USERNAME=<YOUR_NEO4J_USERNAME>
|
||||
NEO4J_PASSWORD=<YOUR_NEO4J_PASSWORD>
|
||||
```
|
||||
|
||||
## Populating with data
|
||||
|
||||
If you want to populate the DB with some example data, you can run `python ingest.py`.
|
||||
This script will populate the database with sample movie data.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
|
@ -1,10 +1,29 @@
|
||||
# Graph Generation Chain for Neo4j Knowledge Graph
|
||||
|
||||
Harness the power of natural language understanding and convert plain text into structured knowledge graphs with the Graph Generation Chain.
|
||||
This system integrates with the Neo4j graph database using OpenAI's LLM.
|
||||
By leveraging OpenAI Functions capabilities, the Graph Generation Chain efficiently extracts graph structure from text.
|
||||
Harness the power of natural language understanding of LLMs and convert plain text into structured knowledge graphs with the Graph Generation Chain.
|
||||
This chain uses OpenAI's LLM to construct a knowledge graph in Neo4j.
|
||||
Leveraging OpenAI Functions capabilities, the Graph Generation Chain efficiently extracts structured information from text.
|
||||
The chain has the following input parameters:
|
||||
|
||||
## Set up Environment
|
||||
* text (str): The input text from which the information will be extracted to construct the graph.
|
||||
* allowed_nodes (Optional[List[str]]): A list of node labels to guide the extraction process.
|
||||
If not provided, extraction won't have specific restriction on node labels.
|
||||
* allowed_relationships (Optional[List[str]]): A list of relationship types to guide the extraction process.
|
||||
If not provided, extraction won't have specific restriction on relationship types.
|
||||
|
||||
Find more details in [this blog post](https://blog.langchain.dev/constructing-knowledge-graphs-from-text-using-openai-functions/).
|
||||
|
||||
## Neo4j database
|
||||
|
||||
There are a number of ways to set up a Neo4j database.
|
||||
|
||||
### Neo4j Aura
|
||||
|
||||
Neo4j AuraDB is a fully managed cloud graph database service.
|
||||
Create a free instance on [Neo4j Aura](https://neo4j.com/cloud/platform/aura-graph-database?utm_source=langchain&utm_content=langserve).
|
||||
When you initiate a free database instance, you'll receive credentials to access the database.
|
||||
|
||||
## Environment variables
|
||||
|
||||
You need to define the following environment variables
|
||||
|
||||
|
@ -1,8 +1,19 @@
|
||||
# Parent Document Retriever with Neo4j Vector Index
|
||||
|
||||
This template allows you to balance precise embeddings and context retention by splitting documents into smaller chunks and retrieving their original or larger text information.
|
||||
Using a Neo4j vector index, the template queries child nodes using vector similarity search and retrieves the corresponding parent's text by defining an appropriate `retrieval_query` parameter.
|
||||
|
||||
## Set up Environment
|
||||
## Neo4j database
|
||||
|
||||
There are a number of ways to set up a Neo4j database.
|
||||
|
||||
### Neo4j Aura
|
||||
|
||||
Neo4j AuraDB is a fully managed cloud graph database service.
|
||||
Create a free instance on [Neo4j Aura](https://neo4j.com/cloud/platform/aura-graph-database?utm_source=langchain&utm_content=langserve).
|
||||
When you initiate a free database instance, you'll receive credentials to access the database.
|
||||
|
||||
## Environment variables
|
||||
|
||||
You need to define the following environment variables
|
||||
|
||||
@ -13,6 +24,14 @@ NEO4J_USERNAME=<YOUR_NEO4J_USERNAME>
|
||||
NEO4J_PASSWORD=<YOUR_NEO4J_PASSWORD>
|
||||
```
|
||||
|
||||
## Populating with data
|
||||
|
||||
If you want to populate the DB with some example data, you can run `python ingest.py`.
|
||||
The script process and stores sections of the text from the file `dune.txt` into a Neo4j graph database.
|
||||
First, the text is divided into larger chunks ("parents") and then further subdivided into smaller chunks ("children"), where both parent and child chunks overlap slightly to maintain context.
|
||||
After storing these chunks in the database, embeddings for the child nodes are computed using OpenAI's embeddings and stored back in the graph for future retrieval or analysis.
|
||||
Additionally, a vector index named `retrieval` is created for efficient querying of these embeddings.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
|
@ -8,6 +8,7 @@ from langchain.vectorstores import Neo4jVector
|
||||
|
||||
retrieval_query = """
|
||||
MATCH (node)-[:HAS_PARENT]->(parent)
|
||||
WITH parent, max(score) AS score // deduplicate parents
|
||||
RETURN parent.text AS text, score, {} AS metadata
|
||||
"""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user