Neo4j graph construction from unstructured data using LLMs
See the code
Transform unstructured data (PDFs, DOCs, TXTs, YouTube videos, web pages, etc.) into a structured Knowledge Graph stored in Neo4j using the power of Large Language Models (LLMs) and the LangChain framework.
This application allows you to upload files from various sources (local machine, GCS, S3 bucket, or web sources), choose your preferred LLM model, and generate a Knowledge Graph.
CALL (variable) { ... }), which is not supported by earlier Neo4j 5.x releases such as 5.20..env file in the backend folder by copying backend/example.env..env file to bypass the login dialog:
NEO4J_URI=<your-neo4j-uri>
NEO4J_USERNAME=<your-username>
NEO4J_PASSWORD=<your-password>
NEO4J_DATABASE=<your-database-name>
cd backend
python3.12 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn score:app --reload
TRACK_USER_USAGE environment variable to true in your backend configuration.TRACK_USER_USAGE is enabled.You have two ways to configure the embedding model locally:
With User Tracking (TRACK_USER_USAGE=true):
TRACK_USER_USAGE to true in your backend .env file.TOKEN_TRACKER_DB_URI, TOKEN_TRACKER_DB_USERNAME, etc.).Without User Tracking (TRACK_USER_USAGE=false):
TRACK_USER_USAGE to false..env file using EMBEDDING_MODEL and EMBEDDING_PROVIDER.CALL (variable) { ... }), which is not supported by earlier Neo4j 5.x releases such as 5.20.Run the application using the default docker-compose configuration.
Supported LLM Models:
By default, only OpenAI and Diffbot are enabled. Gemini requires additional GCP configurations.
Use the VITE_LLM_MODELS_PROD variable to configure the models you need. Example:
VITE_LLM_MODELS_PROD="gemini_3.5_flash,openai_gpt_5.4_mini,diffbot,anthropic_claude_4.5_haiku"
Anthropic Models: Use the latest Claude model in your config:
LLM_MODEL_CONFIG_ANTHROPIC_CLAUDE_4_7_OPUS="claude-opus-4-7,anthropic_api_key"
Input Sources:
By default, the following sources are enabled: local, YouTube, Wikipedia, AWS S3, and web.
To add Google Cloud Storage (GCS) integration, include gcs and your Google client ID:
VITE_REACT_APP_SOURCES="local,youtube,wiki,s3,gcs,web"
VITE_GOOGLE_CLIENT_ID="your-google-client-id"
Configure chat modes using the VITE_CHAT_MODES variable:
vector, graph_vector, graph, fulltext, graph_vector_fulltext, entity_vector, and global_vector.VITE_CHAT_MODES="vector,graph"
For development, you can run the backend and frontend independently.
.env file in the frontend folder by copying frontend/example.env.cd frontend
yarn yarn run dev
#### **Backend Setup**
1. Create a `.env` file in the `backend` folder by copying `backend/example.env`.
2. Pre-configure user credentials in the `.env` file to bypass the login dialog:
```bash
NEO4J_URI=<your-neo4j-uri>
NEO4J_USERNAME=<your-username>
NEO4J_PASSWORD=<your-password>
NEO4J_DATABASE=<your-database-name>
cd backend
python -m venv envName source envName/bin/activate pip install -r requirements.txt uvicorn score:app --reload
---
### **Cloud Deployment**
Deploy the application on **Google Cloud Platform** using the following commands:
#### **Frontend Deployment**
```bash
gcloud run deploy dev-frontend \
--source . \
--region us-central1 \
--allow-unauthenticated
gcloud run deploy dev-backend \
--set-env-vars "OPENAI_API_KEY=<your-openai-api-key>" \
--set-env-vars "DIFFBOT_API_KEY=<your-diffbot-api-key>" \
--set-env-vars "NEO4J_URI=<your-neo4j-uri>" \
--set-env-vars "NEO4J_USERNAME=<your-username>" \
--set-env-vars "NEO4J_PASSWORD=<your-password>" \
--source . \
--region us-central1 \
--allow-unauthenticated
docker pull ollama/ollama
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
docker exec -it ollama ollama run llama3
LLM_MODEL_CONFIG_ollama_<model_name>
# example
LLM_MODEL_CONFIG_ollama_llama3=${LLM_MODEL_CONFIG_ollama_llama3-llama3,http://host.docker.internal:11434}
VITE_BACKEND_API_URL=${VITE_BACKEND_API_URL-backendurl}
| Env Variable Name | Mandatory/Optional | Default Value | Description |
|---|---|---|---|
| BACKEND ENV | |||
| OPENAI_API_KEY | Optional | An OpenAI Key is required to use OpenAI LLM model to authenticate and track requests | |
| DIFFBOT_API_KEY | Mandatory | API key is required to use Diffbot's NLP service to extract entities and relationships from unstructured data | |
| BUCKET_UPLOAD_FILE | Optional | Bucket name to store uploaded file on GCS | |
| BUCKET_FAILED_FILE | Optional | Bucket name to store failed file on GCS while extraction | |
| USER_AGENT | Optional | llm-graph-builder | Name of the user agent to track Neo4j database activity |
| ENABLE_USER_AGENT | Optional | true | Boolean value to enable/disable Neo4j user agent |
| DUPLICATE_TEXT_DISTANCE | Optional | 5 | This value is used to find distance for all node pairs in the graph and is calculated based on node properties |
| DUPLICATE_SCORE_VALUE | Optional | 0.97 | Node score value to match duplicate nodes |
| EFFECTIVE_SEARCH_RATIO | Optional | 1 | Ratio used for effective search calculations |
| GRAPH_CLEANUP_MODEL | Optional | openai_gpt_5_mini | Model name to clean up graph in post processing |
| MAX_TOKEN_CHUNK_SIZE | Optional | 10000 | Maximum token size to process file content |
| YOUTUBE_TRANSCRIPT_PROXY | Mandatory | Proxy key to process YouTube videos for getting transcripts | |
| IS_EMBEDDING | Optional | true | Flag to enable text embedding |
| KNN_MIN_SCORE | Optional | 0.8 | Minimum score for KNN algorithm |
| GCP_LOG_METRICS_ENABLED | Optional | False | Flag to enable Google Cloud logs |
| NEO4J_URI | Optional | neo4j://database:7687 | URI for Neo4j database |
| NEO4J_USERNAME | Optional | neo4j | Username for Neo4j database |
| NEO4J_PASSWORD | Optional | password | Password for Neo4j database |
| GCS_FILE_CACHE | Optional | False | If set to True, will save files to process into GCS. If False, will save files locally |
| ENTITY_EMBEDDING | Optional | False | If set to True, it will add embeddings for each entity in the database |
| LLM_MODEL_CONFIG_ollama_<model_name> | Optional | Set ollama config as model_name,model_local_url for local deployments | |
| FRONTEND ENV | |||
| VITE_BLOOM_URL | Mandatory | Bloom URL | URL for Bloom visualization |
| VITE_REACT_APP_SOURCES | Mandatory | local,youtube,wiki,s3 | List of input sources that will be available |
| VITE_CHAT_MODES | Mandatory | vector,graph+vector,graph,hybrid | Chat modes available for Q&A |
| VITE_ENV | Mandatory | DEV or PROD | Environment variable for the app |
| VITE_LLM_MODELS | Optional | openai_gpt_5_mini,gemini_flash_latest,anthropic_claude_4.5_haiku | Supported models for the application |
| VITE_BACKEND_API_URL | Optional | localhost | URL for backend API |
| VITE_TIME_PER_PAGE | Optional | 50 | Time per page for processing |
| VITE_CHUNK_SIZE | Optional | 5242880 | Size of each chunk of file for upload |
| VITE_GOOGLE_CLIENT_ID | Optional | Client ID for Google authentication | |
| VITE_LLM_MODELS_PROD | Optional | openai_gpt_5_mini,gemini_flash_latest,anthropic_claude_4.5_haiku | To distinguish models based on environment (PROD or DEV) |
| VITE_AUTH0_CLIENT_ID | Mandatory if you are enabling Authentication otherwise it is optional | Okta OAuth Client ID for authentication | |
| VITE_AUTH0_DOMAIN | Mandatory if you are enabling Authentication otherwise it is optional | Okta OAuth Client Domain | |
| VITE_SKIP_AUTH | Optional | true | Flag to skip authentication |
| VITE_CHUNK_OVERLAP | Optional | 20 | Variable to configure chunk overlap |
| VITE_TOKENS_PER_CHUNK | Optional | 100 | Variable to configure tokens count per chunk. This gives flexibility for users who may require different chunk sizes for various tokenization tasks |
| VITE_CHUNK_TO_COMBINE | Optional | 1 | Variable to configure number of chunks to combine for parallel processing |
Refer to the example environment files for additional variables and configuration:
You can deploy the backend and the frontend to Google Cloud Run using Cloud Build, either manually or via automated triggers.
Connect your repository to Google Cloud Build:
main, staging, or dev).cloudbuild.yaml file in the root of your repository.Configure Substitutions and Secrets:
_OPENAI_API_KEY, _DIFFBOT_API_KEY, etc.) as environment variables or use Secret Manager for sensitive data.Push your code:
cloudbuild.yaml.Set up Google Cloud SDK and authenticate:
gcloud auth login
gcloud config set project <YOUR_PROJECT_ID>
Run Cloud Build manually:
gcloud builds submit --config cloudbuild.yaml \
--substitutions=_REGION=us-central1,_REPO=cloud-run-repo,_OPENAI_API_KEY=<your-openai-key>,_DIFFBOT_API_KEY=<your-diffbot-key>,_BUCKET_UPLOAD_FILE=<your-bucket>,_BUCKET_FAILED_FILE=<your-bucket>,_PROJECT_ID=<your-project-id>,_GCS_FILE_CACHE=False,_TRACK_USER_USAGE=False,_TOKEN_TRACKER_DB_URI=...,_TOKEN_TRACKER_DB_USERNAME=...,_TOKEN_TRACKER_DB_PASSWORD=...,_TOKEN_TRACKER_DB_DATABASE=...,_DEFAULT_DIFFBOT_CHAT_MODEL=...,_YOUTUBE_TRANSCRIPT_PROXY=...,_EMBEDDING_MODEL=...,
_EMBEDDING_PROVIDER=...,_BEDROCK_EMBEDDING_MODEL_KEY=...,_LLM_MODEL_CONFIG_OPENAI_GPT_5_2=...,_LLM_MODEL_CONFIG_OPENAI_GPT_5_MINI=...,_LLM_MODEL_CONFIG_GEMINI_2_5_FLASH=...,_LLM_MODEL_CONFIG_GEMINI_2_5_PRO=...,_LLM_MODEL_CONFIG_DIFFBOT=...,_LLM_MODEL_CONFIG_GROQ_LLAMA3_1_8B=...,_LLM_MODEL_CONFIG_ANTHROPIC_CLAUDE_4_5_SONNET=...,_LLM_MODEL_CONFIG_ANTHROPIC_CLAUDE_4_5_HAIKU=...,_LLM_MODEL_CONFIG_LLAMA4_MAVERICK=...,_LLM_MODEL_CONFIG_FIREWORKS_QWEN3_6=...,_LLM_MODEL_CONFIG_FIREWORKS_GPT_OSS=...,_LLM_MODEL_CONFIG_FIREWORKS_DEEPSEEK_V3=...,_LLM_MODEL_CONFIG_BEDROCK_NOVA_MICRO_V1=...,_LLM_MODEL_CONFIG_BEDROCK_NOVA_LITE_V1=...,_LLM_MODEL_CONFIG_BEDROCK_NOVA_PRO_V1=...,_LLM_MODEL_CONFIG_OLLAMA_LLAMA3=...
LLM_MODEL_CONFIG_FIREWORKS_QWEN3_6 is the app-facing config key for the fireworks_qwen3_6 model option and should map to the Fireworks serverless slug accounts/fireworks/models/qwen3p6-plus.Monitor the build:
Access your deployed service:
Note:
cloudbuild.yaml file supports multiple environments (main, staging, dev) based on the branch name.cloudbuild.yaml if you wish to deploy the frontend as well.For more details, see the comments in cloudbuild.yaml.
LLM Knowledge Graph Builder Application
For any inquiries or support, feel free to raise GitHub Issues
335 followers · starred May 2024
46 followers · starred Jul 2024
129 followers · starred Jul 2024
31 followers · starred Nov 2024
Neo4j graph construction from unstructured data using LLMs
See the code
Transform unstructured data (PDFs, DOCs, TXTs, YouTube videos, web pages, etc.) into a structured Knowledge Graph stored in Neo4j using the power of Large Language Models (LLMs) and the LangChain framework.
This application allows you to upload files from various sources (local machine, GCS, S3 bucket, or web sources), choose your preferred LLM model, and generate a Knowledge Graph.
CALL (variable) { ... }), which is not supported by earlier Neo4j 5.x releases such as 5.20..env file in the backend folder by copying backend/example.env..env file to bypass the login dialog:
NEO4J_URI=<your-neo4j-uri>
NEO4J_USERNAME=<your-username>
NEO4J_PASSWORD=<your-password>
NEO4J_DATABASE=<your-database-name>
cd backend
python3.12 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn score:app --reload
TRACK_USER_USAGE environment variable to true in your backend configuration.TRACK_USER_USAGE is enabled.You have two ways to configure the embedding model locally:
With User Tracking (TRACK_USER_USAGE=true):
TRACK_USER_USAGE to true in your backend .env file.TOKEN_TRACKER_DB_URI, TOKEN_TRACKER_DB_USERNAME, etc.).Without User Tracking (TRACK_USER_USAGE=false):
TRACK_USER_USAGE to false..env file using EMBEDDING_MODEL and EMBEDDING_PROVIDER.CALL (variable) { ... }), which is not supported by earlier Neo4j 5.x releases such as 5.20.Run the application using the default docker-compose configuration.
Supported LLM Models:
By default, only OpenAI and Diffbot are enabled. Gemini requires additional GCP configurations.
Use the VITE_LLM_MODELS_PROD variable to configure the models you need. Example:
VITE_LLM_MODELS_PROD="gemini_3.5_flash,openai_gpt_5.4_mini,diffbot,anthropic_claude_4.5_haiku"
Anthropic Models: Use the latest Claude model in your config:
LLM_MODEL_CONFIG_ANTHROPIC_CLAUDE_4_7_OPUS="claude-opus-4-7,anthropic_api_key"
Input Sources:
By default, the following sources are enabled: local, YouTube, Wikipedia, AWS S3, and web.
To add Google Cloud Storage (GCS) integration, include gcs and your Google client ID:
VITE_REACT_APP_SOURCES="local,youtube,wiki,s3,gcs,web"
VITE_GOOGLE_CLIENT_ID="your-google-client-id"
Configure chat modes using the VITE_CHAT_MODES variable:
vector, graph_vector, graph, fulltext, graph_vector_fulltext, entity_vector, and global_vector.VITE_CHAT_MODES="vector,graph"
For development, you can run the backend and frontend independently.
.env file in the frontend folder by copying frontend/example.env.cd frontend
yarn yarn run dev
#### **Backend Setup**
1. Create a `.env` file in the `backend` folder by copying `backend/example.env`.
2. Pre-configure user credentials in the `.env` file to bypass the login dialog:
```bash
NEO4J_URI=<your-neo4j-uri>
NEO4J_USERNAME=<your-username>
NEO4J_PASSWORD=<your-password>
NEO4J_DATABASE=<your-database-name>
cd backend
python -m venv envName source envName/bin/activate pip install -r requirements.txt uvicorn score:app --reload
---
### **Cloud Deployment**
Deploy the application on **Google Cloud Platform** using the following commands:
#### **Frontend Deployment**
```bash
gcloud run deploy dev-frontend \
--source . \
--region us-central1 \
--allow-unauthenticated
gcloud run deploy dev-backend \
--set-env-vars "OPENAI_API_KEY=<your-openai-api-key>" \
--set-env-vars "DIFFBOT_API_KEY=<your-diffbot-api-key>" \
--set-env-vars "NEO4J_URI=<your-neo4j-uri>" \
--set-env-vars "NEO4J_USERNAME=<your-username>" \
--set-env-vars "NEO4J_PASSWORD=<your-password>" \
--source . \
--region us-central1 \
--allow-unauthenticated
docker pull ollama/ollama
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
docker exec -it ollama ollama run llama3
LLM_MODEL_CONFIG_ollama_<model_name>
# example
LLM_MODEL_CONFIG_ollama_llama3=${LLM_MODEL_CONFIG_ollama_llama3-llama3,http://host.docker.internal:11434}
VITE_BACKEND_API_URL=${VITE_BACKEND_API_URL-backendurl}
| Env Variable Name | Mandatory/Optional | Default Value | Description |
|---|---|---|---|
| BACKEND ENV | |||
| OPENAI_API_KEY | Optional | An OpenAI Key is required to use OpenAI LLM model to authenticate and track requests | |
| DIFFBOT_API_KEY | Mandatory | API key is required to use Diffbot's NLP service to extract entities and relationships from unstructured data | |
| BUCKET_UPLOAD_FILE | Optional | Bucket name to store uploaded file on GCS | |
| BUCKET_FAILED_FILE | Optional | Bucket name to store failed file on GCS while extraction | |
| USER_AGENT | Optional | llm-graph-builder | Name of the user agent to track Neo4j database activity |
| ENABLE_USER_AGENT | Optional | true | Boolean value to enable/disable Neo4j user agent |
| DUPLICATE_TEXT_DISTANCE | Optional | 5 | This value is used to find distance for all node pairs in the graph and is calculated based on node properties |
| DUPLICATE_SCORE_VALUE | Optional | 0.97 | Node score value to match duplicate nodes |
| EFFECTIVE_SEARCH_RATIO | Optional | 1 | Ratio used for effective search calculations |
| GRAPH_CLEANUP_MODEL | Optional | openai_gpt_5_mini | Model name to clean up graph in post processing |
| MAX_TOKEN_CHUNK_SIZE | Optional | 10000 | Maximum token size to process file content |
| YOUTUBE_TRANSCRIPT_PROXY | Mandatory | Proxy key to process YouTube videos for getting transcripts | |
| IS_EMBEDDING | Optional | true | Flag to enable text embedding |
| KNN_MIN_SCORE | Optional | 0.8 | Minimum score for KNN algorithm |
| GCP_LOG_METRICS_ENABLED | Optional | False | Flag to enable Google Cloud logs |
| NEO4J_URI | Optional | neo4j://database:7687 | URI for Neo4j database |
| NEO4J_USERNAME | Optional | neo4j | Username for Neo4j database |
| NEO4J_PASSWORD | Optional | password | Password for Neo4j database |
| GCS_FILE_CACHE | Optional | False | If set to True, will save files to process into GCS. If False, will save files locally |
| ENTITY_EMBEDDING | Optional | False | If set to True, it will add embeddings for each entity in the database |
| LLM_MODEL_CONFIG_ollama_<model_name> | Optional | Set ollama config as model_name,model_local_url for local deployments | |
| FRONTEND ENV | |||
| VITE_BLOOM_URL | Mandatory | Bloom URL | URL for Bloom visualization |
| VITE_REACT_APP_SOURCES | Mandatory | local,youtube,wiki,s3 | List of input sources that will be available |
| VITE_CHAT_MODES | Mandatory | vector,graph+vector,graph,hybrid | Chat modes available for Q&A |
| VITE_ENV | Mandatory | DEV or PROD | Environment variable for the app |
| VITE_LLM_MODELS | Optional | openai_gpt_5_mini,gemini_flash_latest,anthropic_claude_4.5_haiku | Supported models for the application |
| VITE_BACKEND_API_URL | Optional | localhost | URL for backend API |
| VITE_TIME_PER_PAGE | Optional | 50 | Time per page for processing |
| VITE_CHUNK_SIZE | Optional | 5242880 | Size of each chunk of file for upload |
| VITE_GOOGLE_CLIENT_ID | Optional | Client ID for Google authentication | |
| VITE_LLM_MODELS_PROD | Optional | openai_gpt_5_mini,gemini_flash_latest,anthropic_claude_4.5_haiku | To distinguish models based on environment (PROD or DEV) |
| VITE_AUTH0_CLIENT_ID | Mandatory if you are enabling Authentication otherwise it is optional | Okta OAuth Client ID for authentication | |
| VITE_AUTH0_DOMAIN | Mandatory if you are enabling Authentication otherwise it is optional | Okta OAuth Client Domain | |
| VITE_SKIP_AUTH | Optional | true | Flag to skip authentication |
| VITE_CHUNK_OVERLAP | Optional | 20 | Variable to configure chunk overlap |
| VITE_TOKENS_PER_CHUNK | Optional | 100 | Variable to configure tokens count per chunk. This gives flexibility for users who may require different chunk sizes for various tokenization tasks |
| VITE_CHUNK_TO_COMBINE | Optional | 1 | Variable to configure number of chunks to combine for parallel processing |
Refer to the example environment files for additional variables and configuration:
You can deploy the backend and the frontend to Google Cloud Run using Cloud Build, either manually or via automated triggers.
Connect your repository to Google Cloud Build:
main, staging, or dev).cloudbuild.yaml file in the root of your repository.Configure Substitutions and Secrets:
_OPENAI_API_KEY, _DIFFBOT_API_KEY, etc.) as environment variables or use Secret Manager for sensitive data.Push your code:
cloudbuild.yaml.Set up Google Cloud SDK and authenticate:
gcloud auth login
gcloud config set project <YOUR_PROJECT_ID>
Run Cloud Build manually:
gcloud builds submit --config cloudbuild.yaml \
--substitutions=_REGION=us-central1,_REPO=cloud-run-repo,_OPENAI_API_KEY=<your-openai-key>,_DIFFBOT_API_KEY=<your-diffbot-key>,_BUCKET_UPLOAD_FILE=<your-bucket>,_BUCKET_FAILED_FILE=<your-bucket>,_PROJECT_ID=<your-project-id>,_GCS_FILE_CACHE=False,_TRACK_USER_USAGE=False,_TOKEN_TRACKER_DB_URI=...,_TOKEN_TRACKER_DB_USERNAME=...,_TOKEN_TRACKER_DB_PASSWORD=...,_TOKEN_TRACKER_DB_DATABASE=...,_DEFAULT_DIFFBOT_CHAT_MODEL=...,_YOUTUBE_TRANSCRIPT_PROXY=...,_EMBEDDING_MODEL=...,
_EMBEDDING_PROVIDER=...,_BEDROCK_EMBEDDING_MODEL_KEY=...,_LLM_MODEL_CONFIG_OPENAI_GPT_5_2=...,_LLM_MODEL_CONFIG_OPENAI_GPT_5_MINI=...,_LLM_MODEL_CONFIG_GEMINI_2_5_FLASH=...,_LLM_MODEL_CONFIG_GEMINI_2_5_PRO=...,_LLM_MODEL_CONFIG_DIFFBOT=...,_LLM_MODEL_CONFIG_GROQ_LLAMA3_1_8B=...,_LLM_MODEL_CONFIG_ANTHROPIC_CLAUDE_4_5_SONNET=...,_LLM_MODEL_CONFIG_ANTHROPIC_CLAUDE_4_5_HAIKU=...,_LLM_MODEL_CONFIG_LLAMA4_MAVERICK=...,_LLM_MODEL_CONFIG_FIREWORKS_QWEN3_6=...,_LLM_MODEL_CONFIG_FIREWORKS_GPT_OSS=...,_LLM_MODEL_CONFIG_FIREWORKS_DEEPSEEK_V3=...,_LLM_MODEL_CONFIG_BEDROCK_NOVA_MICRO_V1=...,_LLM_MODEL_CONFIG_BEDROCK_NOVA_LITE_V1=...,_LLM_MODEL_CONFIG_BEDROCK_NOVA_PRO_V1=...,_LLM_MODEL_CONFIG_OLLAMA_LLAMA3=...
LLM_MODEL_CONFIG_FIREWORKS_QWEN3_6 is the app-facing config key for the fireworks_qwen3_6 model option and should map to the Fireworks serverless slug accounts/fireworks/models/qwen3p6-plus.Monitor the build:
Access your deployed service:
Note:
cloudbuild.yaml file supports multiple environments (main, staging, dev) based on the branch name.cloudbuild.yaml if you wish to deploy the frontend as well.For more details, see the comments in cloudbuild.yaml.
LLM Knowledge Graph Builder Application
For any inquiries or support, feel free to raise GitHub Issues
335 followers · starred May 2024
46 followers · starred Jul 2024
129 followers · starred Jul 2024
31 followers · starred Nov 2024