How bhavy-ranka/graphitti works
Purpose and Entry Points
Graphitti builds a temporary, graph-native knowledge base from a crawled website, then answers questions using routed text and graph retrieval. The primary backend entry point is graphitti/api/app.py; interactive use is through graphitti/streamlit_app.py. The API serves an interactive graph view from graphitti/api/static/graph.html.
Ingestion Control Flow
An ingest request orchestrates crawl-to-graph construction. By default it resets prior graph and text-index state, enforcing a single active crawled corpus. The central workflow is implemented in graphitti/orchestration/orchestrator.py, using crawl output from graphitti/crawling/crawler.py and graph loading in graphitti/graph/loader.py.
Crawl and Local Extraction
The crawler performs breadth-first browser crawling with Playwright in graphitti/crawling/crawler.py. Page text is segmented into sentence-aware chunks by graphitti/extraction/chunking.py. graphitti/extraction/nlp_pipeline.py and graphitti/extraction/triple_extractor.py derive entity-relation-entity triples locally with NLTK POS tagging, NER, grammar rules, SVO/passive handling, pronoun heuristics, and confidence scoring; extraction does not call an LLM.
Entity and Graph Quality Boundary
Extracted triples use typed schemas in graphitti/extraction/schemas.py, then pass through direction normalization and alias/entity merging in graphitti/extraction/direction.py and graphitti/extraction/entity_resolution.py. Graph conflict detection marks contested relationships before persistence in graphitti/graph/consistency.py. This separates noisy web-text interpretation from graph storage and retrieval.
Graph and Text Persistence
graphitti/graph/store.py provides Neo4j and in-memory graph-store implementations. graphitti/graph/loader.py batch-loads nodes and edges through Neo4j UNWIND/MERGE operations with rollback behavior. Raw chunks remain addressable in graphitti/retrieval/text_index.py for textual evidence and citations. Neo4j is the material external persistence dependency; Playwright/Chromium is required for crawling.
Query Routing and Retrieval
Questions enter intent classification and decomposition chains in graphitti/routing/chains.py, with strategy selection and confidence fallback in graphitti/routing/query_router.py. Low-confidence routing selects hybrid retrieval. Available evidence sources are BM25 (graphitti/retrieval/bm25.py), dense vector search with Sentence-Transformers or TF-IDF fallback (graphitti/retrieval/dense.py), and entity/multi-hop graph traversal (graphitti/retrieval/graph_retrieval.py). graphitti/retrieval/base.py registers strategies and combines rankings with reciprocal-rank fusion.
Answer Orchestration and Presentation
A LangGraph state machine coordinates routing, retrieval, and final synthesis in graphitti/orchestration/orchestrator.py. graphitti/orchestration/synthesis_chain.py produces provenance-backed answers from retrieved graph/text evidence. FastAPI exposes ingest, query, and graph-facing operations in graphitti/api/app.py; Streamlit drives those APIs and refreshes the visualized graph after each reset-and-ingest cycle.
Main entry points: base.py Evidence Retrieval · app.py FastAPI API · orchestrator.py Workflow Orchestrator · chunking.py Sentence Chunking
Components 22
Interfaces
- Streamlit UI · Drives API workflows and graph refreshes.
graphitti/streamlit_app.py - FastAPI API · Exposes ingest, query, and graph operations.
graphitti/api/app.py - Graph Viewer
graphitti/api/static/graph.html
Ingestion
- Workflow Orchestrator · Coordinates ingestion and routed answer generation.
graphitti/orchestration/orchestrator.py - Browser Crawler · Crawls website pages through Chromium.
graphitti/crawling/crawler.py - Sentence Chunking
graphitti/extraction/chunking.py - Local Triple Extraction · Derives scored entity-relation-entity triples without an LLM.
graphitti/extraction/nlp_pipeline.py - Triple Rules · Handles SVO, passive voice, and pronoun heuristics.
graphitti/extraction/triple_extractor.py - Triple Schemas
graphitti/extraction/schemas.py - Entity Quality · Normalizes relation direction and merges aliases.
graphitti/extraction/entity_resolution.py
Knowledge Store
- Conflict Detection · Marks contested relationships before persistence.
graphitti/graph/consistency.py - Graph Loader · Loads nodes and edges with rollback behavior.
graphitti/graph/loader.py - Graph Store · Provides Neo4j and in-memory implementations.
graphitti/graph/store.py - Neo4j · Material graph persistence dependency.
- Text Index · Keeps raw chunks addressable for evidence and citations.
graphitti/retrieval/text_index.py
Query & Answering
- Query Router · Selects retrieval strategy and falls back to hybrid on low confidence.
graphitti/routing/query_router.py - Intent Chains · Classifies and decomposes questions.
graphitti/routing/chains.py - Evidence Retrieval · Combines BM25, dense, and graph rankings with reciprocal-rank fusion.
graphitti/retrieval/base.py - BM25 Search
graphitti/retrieval/bm25.py - Dense Search · Uses Sentence-Transformers or TF-IDF fallback.
graphitti/retrieval/dense.py - Graph Traversal · Performs entity and multi-hop traversal.
graphitti/retrieval/graph_retrieval.py - Answer Synthesis · Produces answers from graph and text evidence.
graphitti/orchestration/synthesis_chain.py
Connections 25
- Streamlit UI → FastAPI API: uses
- FastAPI API → Graph Viewer: serves
- FastAPI API → Workflow Orchestrator: ingest and query
- Workflow Orchestrator → Browser Crawler: crawl
- Browser Crawler → Sentence Chunking: page text
- Sentence Chunking → Local Triple Extraction: chunks
- Local Triple Extraction → Triple Rules: extracts via
- Triple Rules → Triple Schemas: typed triples
- Triple Schemas → Entity Quality: normalize and merge
- Entity Quality → Conflict Detection: validated triples
- Conflict Detection → Graph Loader: loadable graph
- Graph Loader → Graph Store: batch writes
- Graph Store → Neo4j: persists
- Sentence Chunking → Text Index: raw chunks
- Workflow Orchestrator → Query Router: questions
- Query Router → Intent Chains: classify and decompose
- Query Router → Evidence Retrieval: strategy
- Evidence Retrieval → BM25 Search: text search
- Evidence Retrieval → Dense Search: vector search
- Evidence Retrieval → Graph Traversal: graph search
- BM25 Search → Text Index: searches
- Dense Search → Text Index: searches
- Graph Traversal → Graph Store: traverses
- Evidence Retrieval → Answer Synthesis: ranked evidence
- Answer Synthesis → FastAPI API: answer