Skip to content

About

Semantic RAG — Ontology + Neo4j + LangGraph + Anthropic

Resources

Stars

30 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Semantic RAG — Ontology + Neo4j + LangGraph + Anthropic

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

Architecture

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    │    │              │
└─────────┘    └──────────────┘

Quickstart

Prerequisites

  • Python 3.11+
  • Neo4j (local or AuraDB)
  • Anthropic API key

1. Install dependencies

pip install -r requirements.txt

2. Configure environment

cp .env.example .env
# Edit .env with your Neo4j and Anthropic credentials

3. Seed Neo4j with product data

python data/seed_neo4j.py

4. Start the backend

uvicorn backend.main:app --reload --port 8000

5. Start the frontend

streamlit run frontend/app.py

Open http://localhost:8501


Project Structure

semantic-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

What each layer does in the code:

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.

About

Semantic RAG — Ontology + Neo4j + LangGraph + Anthropic

Resources

Stars

30 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages