Build Knowledge Graphs with txt2kg
Extract triples with Ollama or vLLM, store them in a graph database, and explore them in a GPU-accelerated web UI
Clone the repository
In a terminal, clone the playbook repository and navigate to the project assets directory.
git clone https://github.com/NVIDIA/dgx-spark-playbooks
cd dgx-spark-playbooks/nvidia/playbook-txt2kg/assets
Start the txt2kg services
Use the provided start script. By default, ./start.sh starts the ArangoDB + Ollama stack. Use one stack flag when you want a different graph database or LLM backend.
./start.sh
Common options:
# Stack flags
./start.sh --neo4j # Neo4j + Ollama
./start.sh --vllm # Neo4j + vLLM
# Optional flags
./start.sh --vector-search # Add Qdrant + Sentence Transformers
./start.sh --help # Full option list
DGX Spark is not affected by the 64 KB page-size issue. On affected DGX Station systems, start with ./start.sh --neo4j to use Neo4j + Ollama.
The script will:
- Check for GPU availability
- Start Docker Compose services for the selected stack
- For the vLLM stack, start the backend container; model load can take 30+ minutes, and progress is available with
docker logs vllm-service -f - Print the web UI URL when ready
Choose and load a model
Triple extraction quality depends on the LLM behind Ollama or vLLM. Start with the stack default below, then explore other models to trade quality vs. speed and memory.
Defaults by stack
| Stack | Default model | Notes |
|---|---|---|
| ArangoDB + Ollama | llama3.1:8b | Pull with docker exec ollama-compose ollama pull llama3.1:8b |
| Neo4j + Ollama | llama3.1:8b | Pull with docker exec ollama-compose ollama pull llama3.1:8b |
| Neo4j + vLLM | nvidia/Llama-3_3-Nemotron-Super-49B-v1_5-FP8 | Loaded by the vLLM container; first start can take 30+ minutes |
Ollama stacks
Pull a language model for knowledge extraction (skip if the default was already pulled on start):
docker exec ollama-compose ollama pull <model-name>
Examples:
docker exec ollama-compose ollama pull llama3.1:8b
Then select the model in the web UI.
Explore more models: browse the Ollama model library. Prefer models that fit the memory available on your hardware platform.
vLLM stack
The model is loaded automatically by the vLLM container from VLLM_MODEL in deploy/compose/docker-compose.vllm.yml.
To try a different Hugging Face checkpoint:
- Set
VLLM_MODELto another handle (for example from Hugging Face Models or vLLM Recipes). - Restart:
./stop.shthen start again with your stack flags (for example./start.sh --vllm). - Confirm readiness:
docker logs vllm-service -f
Explore more models: vLLM Recipes — DGX Spark · vLLM Recipes — DGX Station · Hugging Face
NOTE
Larger models generally produce higher-quality triples but need more memory and load time. If you hit memory limits, choose a smaller or quantized model.
Access the web interface
Open your browser and navigate to:
http://localhost:3001
You can also access stack-specific services:
| Service | URL | Stack |
|---|---|---|
| Web UI | http://localhost:3001 | All |
| ArangoDB Web Interface | http://localhost:8529 | ArangoDB + Ollama |
| Neo4j Browser | http://localhost:7474 | Neo4j + Ollama or Neo4j + vLLM |
| Ollama API | http://localhost:11434 | ArangoDB + Ollama or Neo4j + Ollama |
| vLLM API | http://localhost:8001 | Neo4j + vLLM |
Upload documents and build knowledge graphs
If the LLM backend is still loading, the UI may show an initializing banner until the backend is ready.
5.1. Document upload
- Upload text documents (markdown, text, and CSV are supported)
- Documents are chunked and processed for triple extraction
5.2. Knowledge graph generation
- The system extracts subject–predicate–object triples using the selected LLM (Ollama or vLLM)
- Triples are stored in the selected graph database: ArangoDB for the default stack, or Neo4j when started with
--neo4jor--vllm
5.3. Interactive visualization
- View the knowledge graph in 2D or 3D with GPU-accelerated rendering
- Explore nodes and relationships interactively
5.4. Graph-based queries
- Ask questions about your documents in the query interface
- Graph traversal enriches context with entity relationships
- The LLM generates responses using the enriched graph context
Cleanup and rollback
Stop services with the same stack flags you used to start:
# Stop services (match the stack you started)
./stop.sh
# If you started with Neo4j + Ollama: ./stop.sh --neo4j
# If you started with Neo4j + vLLM: ./stop.sh --vllm
# Remove containers and volumes (optional)
# Ollama stack:
# docker compose -f deploy/compose/docker-compose.yml down -v
# Neo4j + Ollama stack:
# docker compose -f deploy/compose/docker-compose.neo4j.yml down -v
# Neo4j + vLLM stack:
# docker compose -f deploy/compose/docker-compose.vllm.yml down -v
# Remove downloaded Ollama models (Ollama stacks only, optional)
# docker exec ollama-compose ollama rm <model-name>
Next steps
- Experiment with different models (Step 3 links) for extraction quality vs. speed
- Customize triple extraction prompts for domain-specific knowledge
- Explore advanced graph querying and visualization features