How azure-samples/graphrag-legalcases-postgres works
This is a legal-research copilot combining vector search, semantic ranking, and citation-graph GraphRAG over U.S. case law. The user asks a question in the chat UI, which sends it to the chat API; the selected RAG flow prepares context using PostgreSQL retrieval and returns an answer and analysis for display. Data ingestion and graph preparation are included as separate product stages. Relationships are limited to those shown in excerpts or documented in the README; unsampled subsystem links are omitted or marked unverified.
Main entry points: Chat.tsx Chat workflow · postgres_searcher.py PostgreSQL retrieval · api_routes.py Chat API routes · rag_advanced.py Advanced RAG flow
Components 22
Chat experience
- Chat workflow
src/frontend/src/pages/chat/Chat.tsx - Chat state
src/frontend/src/AppStateContext/AppStateContext.tsx - Question input
src/frontend/src/components/QuestionInput/QuestionInput.tsx - Answer display
src/frontend/src/components/Answer/Answer.tsx - Analysis panel
src/frontend/src/components/AnalysisPanel/AnalysisPanel.tsx - Graph panel
src/frontend/src/components/AnalysisPanel/GraphPanel.tsx - API client
src/frontend/src/api/models.ts
Application and RAG
- Chat API routes
src/backend/fastapi_app/routes/api_routes.py - Request models
src/backend/fastapi_app/api_models.py - Runtime dependencies
src/backend/fastapi_app/dependencies.py - Advanced RAG flow
src/backend/fastapi_app/rag_advanced.py - Simple RAG flow
src/backend/fastapi_app/rag_simple.py - RAG base
src/backend/fastapi_app/rag_base.py - Query rewriting
src/backend/fastapi_app/query_rewriter.py
Case data and retrieval
- Case ingestion
Data_ingestion/run_headless_data_ingest.py - Case records
src/backend/fastapi_app/postgres_models.py - PostgreSQL retrieval
src/backend/fastapi_app/postgres_searcher.py - PostgreSQL case store
src/backend/fastapi_app/postgres_engine.py
Models and services
- Embedding client
src/backend/fastapi_app/embeddings.py - OpenAI clients
src/backend/fastapi_app/openai_clients.py - Semantic ranker
Other components
- Legal researcher
Connections 23
- Legal researcher → Chat workflow: asks question
src/frontend/src/pages/chat/Chat.tsx - Chat workflow → Question input: renders input
src/frontend/src/pages/chat/Chat.tsx - Chat workflow → Chat state: reads state
src/frontend/src/pages/chat/Chat.tsx - Chat workflow → API client: requests completion
src/frontend/src/pages/chat/Chat.tsx - API client → Chat API routes: sends chat request
- Chat API routes → Request models: accepts request
src/backend/fastapi_app/routes/api_routes.py - Chat API routes → Runtime dependencies: uses dependencies
src/backend/fastapi_app/routes/api_routes.py - Chat API routes → Advanced RAG flow: dispatches advanced flow
src/backend/fastapi_app/routes/api_routes.py - Chat API routes → Simple RAG flow: dispatches simple flow
src/backend/fastapi_app/routes/api_routes.py - Advanced RAG flow → PostgreSQL retrieval: retrieves context
src/backend/fastapi_app/rag_advanced.py - Simple RAG flow → PostgreSQL retrieval: retrieves context
src/backend/fastapi_app/rag_simple.py - Advanced RAG flow → Query rewriting: rewrites queries
src/backend/fastapi_app/rag_advanced.py - Advanced RAG flow → RAG base: uses base flow
src/backend/fastapi_app/rag_advanced.py - Simple RAG flow → RAG base: uses base flow
src/backend/fastapi_app/rag_simple.py - PostgreSQL retrieval → Embedding client: computes query embedding
src/backend/fastapi_app/postgres_searcher.py - PostgreSQL retrieval → PostgreSQL case store: queries cases
src/backend/fastapi_app/postgres_searcher.py - PostgreSQL retrieval → Case records: maps results
src/backend/fastapi_app/postgres_searcher.py - Chat workflow → Answer display: renders answer
src/frontend/src/pages/chat/Chat.tsx - Chat workflow → Analysis panel: renders analysis
src/frontend/src/pages/chat/Chat.tsx - Graph panel → Chat state: reads state
src/frontend/src/components/AnalysisPanel/GraphPanel.tsx - Case ingestion → PostgreSQL case store: loads case data
- PostgreSQL retrieval → Semantic ranker: may rerank results
README.md - OpenAI clients → Advanced RAG flow: provides chat model