# kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python architecture

> Architecture diagram of the GitHub repository kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python
- Repository: https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python

## Overview

Contradiction-Aware Graph RAG serves a TF-IDF top-K baseline and a Neo4j-backed API that identifies an entity/attribute pair, retrieves its recorded facts, and reports agreement or conflict without suppressing sources. The corpus can also be regenerated as synthetic provenance facts. The sampled application and graph-builder source support the runtime edges; the README documents the API capabilities. The graph omits evaluation and deployment tooling, which are not runtime product components.

Main entry points: [`app/main.py`](https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/app/main.py) (API routes), [`ingestion/graph_builder.py`](https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/ingestion/graph_builder.py) (Graph builder), [`data/dataset.json`](https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/data/dataset.json) (Fact dataset), [`scripts/generate_dataset.py`](https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/scripts/generate_dataset.py) (Corpus generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and orchestration"]
  node_api_routes["API routes<br/>[main.py]"]
  node_lifespan["App lifecycle<br/>[main.py]"]
  node_response_models["Response models<br/>[main.py]"]
end

subgraph group_retrieval["Question retrieval"]
  node_target_match["Target matching<br/>[main.py]"]
  node_baseline_search["TF-IDF search<br/>[main.py]"]
  node_graph_retrieval["Fact retrieval<br/>[graph_builder.py]"]
  node_conflict_classifier["Conflict classifier<br/>[main.py]"]
end

subgraph group_knowledge["Knowledge graph"]
  node_graph_builder["Graph builder<br/>[graph_builder.py]"]
  node_neo4j[("Neo4j")]
end

subgraph group_corpus["Fact corpus"]
  node_dataset["Fact dataset<br/>[dataset.json]"]
  node_corpus_generator["Corpus generator"]
end

node_user(("Questioner"))

node_user -->|"submits question"| node_api_routes
node_api_routes -->|"validates response"| node_response_models
node_api_routes -->|"runs baseline"| node_baseline_search
node_baseline_search -->|"reads facts"| node_dataset
node_api_routes -->|"identifies target"| node_target_match
node_api_routes -->|"fetches target facts"| node_graph_retrieval
node_api_routes -->|"lists targets"| node_graph_retrieval
node_api_routes -->|"classifies facts"| node_conflict_classifier
node_lifespan -->|"creates and closes"| node_graph_builder
node_lifespan -->|"loads for ingestion"| node_dataset
node_lifespan -->|"ingests facts"| node_graph_builder
node_graph_builder -->|"writes and queries"| node_neo4j
node_corpus_generator -->|"generates corpus"| node_dataset

click node_api_routes "https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/app/main.py"
click node_lifespan "https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/app/main.py"
click node_response_models "https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/app/main.py"
click node_target_match "https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/app/main.py"
click node_baseline_search "https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/app/main.py"
click node_graph_retrieval "https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/ingestion/graph_builder.py"
click node_conflict_classifier "https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/app/main.py"
click node_graph_builder "https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/ingestion/graph_builder.py"
click node_dataset "https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/data/dataset.json"
click node_corpus_generator "https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/scripts/generate_dataset.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_api_routes,node_lifespan,node_response_models toneBlue
class node_target_match,node_baseline_search,node_graph_retrieval,node_conflict_classifier toneAmber
class node_graph_builder,node_neo4j toneMint
class node_dataset,node_corpus_generator toneRose
class node_user toneIndigo
```

## Components

### API and orchestration

- [API routes](https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/app/main.py): `app/main.py`
- [App lifecycle](https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/app/main.py): `app/main.py`
- [Response models](https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/app/main.py): `app/main.py`

### Question retrieval

- [Target matching](https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/app/main.py): `app/main.py`
- [TF-IDF search](https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/app/main.py): `app/main.py`
- [Fact retrieval](https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/ingestion/graph_builder.py): `ingestion/graph_builder.py`
- [Conflict classifier](https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/app/main.py): `app/main.py`

### Knowledge graph

- [Graph builder](https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/ingestion/graph_builder.py): `ingestion/graph_builder.py`
- **Neo4j**

### Fact corpus

- [Fact dataset](https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/data/dataset.json): `data/dataset.json`
- [Corpus generator](https://github.com/kesavakantipudi/contradiction-aware-graph-rag-system-with-neo4j-fastapi-and-python/blob/main/scripts/generate_dataset.py): `scripts/generate_dataset.py`

### Other components

- **Questioner**

## Connections

- Questioner → API routes: submits question (evidence: `README.md`)
- API routes → Response models: validates response (evidence: `app/main.py`)
- API routes → TF-IDF search: runs baseline (evidence: `app/main.py`)
- TF-IDF search → Fact dataset: reads facts (evidence: `app/main.py`)
- API routes → Target matching: identifies target (evidence: `app/main.py`)
- API routes → Fact retrieval: fetches target facts (evidence: `app/main.py`)
- API routes → Fact retrieval: lists targets (evidence: `app/main.py`)
- API routes → Conflict classifier: classifies facts (evidence: `app/main.py`)
- App lifecycle → Graph builder: creates and closes (evidence: `app/main.py`)
- App lifecycle → Fact dataset: loads for ingestion (evidence: `app/main.py`)
- App lifecycle → Graph builder: ingests facts (evidence: `app/main.py`)
- Graph builder → Neo4j: writes and queries (evidence: `ingestion/graph_builder.py`)
- Corpus generator → Fact dataset: generates corpus (evidence: `scripts/generate_dataset.py`)
