A production-style architecture that demonstrates:
- Ontology — semantic rules engine resolving user language to typed domain concepts
- Neo4j — knowledge graph storing verified product facts and relationships
- LangGraph — orchestration layer mapping intent → ontology → KG → grounded LLM prompt
- Anthropic Claude — language generation only, guided by validated facts
- Streamlit — interactive frontend with live orchestration trace
User Query
│
▼
┌─────────────────────────────────┐
│ STREAMLIT FRONTEND │
│ - Chat UI │
│ - Orchestration trace panel │
└────────────┬────────────────────┘
│ HTTP POST /query
▼
┌─────────────────────────────────┐
│ FASTAPI + LANGGRAPH │
│ │
│ Node 1: resolve_intent │ ← Ontology layer
│ Node 2: validate_constraints │ ← Ontology validation
│ Node 3: query_knowledge_graph │ ← Neo4j query
│ Node 4: build_prompt │ ← Grounded prompt builder
│ Node 5: generate_response │ ← Anthropic Claude
└────────────┬────────────────────┘
│
┌───────┴────────┐
│ │
▼ ▼
┌─────────┐ ┌──────────────┐
│ Neo4j │ │ Anthropic │
│ Graph │ │ Claude API │
│ DB │ │ │
└─────────┘ └──────────────┘
- Python 3.11+
- Neo4j (local or AuraDB)
- Anthropic API key
pip install -r requirements.txtcp .env.example .env
# Edit .env with your Neo4j and Anthropic credentialspython data/seed_neo4j.pyuvicorn backend.main:app --reload --port 8000streamlit run frontend/app.pysemantic-rag/
├── backend/
│ ├── main.py # FastAPI app + LangGraph pipeline
│ ├── graph/
│ │ ├── neo4j_client.py # Neo4j connection + query runner
│ │ └── queries.py # Cypher query templates
│ ├── ontology/
│ │ └── ecommerce.py # Domain ontology: concepts, rules, resolver
│ └── orchestration/
│ └── pipeline.py # LangGraph state graph
├── frontend/
│ └── app.py # Streamlit UI
├── data/
│ └── seed_neo4j.py # Loads product data into Neo4j
├── .env.example
├── requirements.txt
└── README.md
backend/ontology/ecommerce.py — the semantic rules engine. Resolves "blue waterproof jacket under $200 size M" into typed concepts using regex + domain vocabulary, then validates attribute combinations against rules (e.g. removes waterproof if the category is headphones).
backend/graph/queries.py — Cypher query that uses Neo4j's EXISTS {} pattern to filter by features, sizes, and shipping — all as independent graph traversals, not string matching.
backend/orchestration/pipeline.py — the LangGraph state graph with 5 explicit nodes: resolve_intent → validate_constraints → query_knowledge_graph → build_prompt → generate_response. State flows through all nodes so the full trace is always available.
backend/main.py — FastAPI wrapper that exposes /query and /health.
frontend/app.py — Streamlit two-column layout: left side is the chat, right side is the live orchestration trace showing ontology annotations, KG filter params, matched products, and per-node timing bars. Every query's trace is preserved and collapsible.