Local-first • Azure-ready • Explainable

Structure-aware RAG for technical document intelligence.

FoundryRAG is a hybrid retrieval system designed for industrial and engineering documents. It preserves hierarchy, reconstructs full sections, exposes the complete retrieval trace, and runs with either Microsoft Foundry Local or Azure AI services.

Author: Mahmut Esat KolayContext: Microsoft Türkiye AI Innovators Summer Internship
Document entity graph generated by FoundryRAG
0.982Recall@5
0.905Mean Reciprocal Rank
27s → 4sQuery expansion optimization
Local + CloudUnified execution architecture
Why FoundryRAG

More than flat chunking and a prompt wrapper.

The project was built as an observable retrieval system with explicit architectural controls, measurable behavior, and source-level verification.

01

KnowledgeNode tree

Documents are represented as headings, paragraphs, tables, figures, notes, and warnings. Tables remain atomic and hierarchy is preserved through parent identifiers and heading paths.

02

Full section reconstruction

Retrieved evidence is not sent as an isolated sentence. Sibling nodes from the same parent section are reconstructed to restore complete technical context.

03

Bounded multi-hop

When confidence is low, the system performs at most one additional retrieval round without entering an unpredictable agent loop.

04

Honest failure handling

If reliable generation is not possible, FoundryRAG returns an explicit failure message and still exposes the retrieved references.

05

Real-time explainability

The interface exposes nodes, sources, pages, rerank scores, query tracks, retrieval hops, and stage-level latency.

06

Local-first architecture

Node-tree and entity-graph logic stay local while retrieval and generation backends can switch between local and Azure services.

Architecture

One retrieval design, two execution modes.

The same structural and retrieval logic can be executed locally or with Azure services.

Overall system architecture

Overall system architecture

FastAPI connects the chat interface, ingestion pipeline, retrieval system, SQLite storage, entity graph, and local or cloud LLM backends.

Local and cloud architecture

Local and cloud separation

Local mode uses SQLite, SentenceTransformer, and Foundry Local. Cloud mode integrates Azure Blob Storage, Azure AI Search, and Azure OpenAI.

Retrieval pipeline

From document structure to a grounded answer.

Each stage has a focused responsibility and is observable through interface telemetry.

01

Structure-aware ingestion

PDF, DOCX, Markdown, and XLSX files are parsed into a KnowledgeNode tree. Hash deduplication prevents repeated ingestion and an entity graph is created.

02

Query rewriting and expansion

The question is rewritten into up to three domain-agnostic variants. Embeddings can be generated locally or through Azure OpenAI.

03

Hybrid retrieval

BM25 captures exact terminology while dense search captures semantic similarity. Reciprocal Rank Fusion combines both result sets.

04

Reranking and grading

A cross-encoder reranks candidates. The grader applies deduplication, keyword overlap, and score filtering.

05

Context reconstruction

Full parent sections are reconstructed. If confidence remains low, one bounded follow-up retrieval hop is allowed.

06

Grounded generation

The final context is sent to Foundry Local or Azure OpenAI. Loop detection and honest failure handling protect answer reliability.

Document ingestion pipeline

Document ingestion pipeline

Typed node extraction, structure-aware chunking, deduplication, storage, and entity graph construction.

RAG pipeline

End-to-end RAG flow

Query rewrite, hybrid retrieval, reranking, grading, context optimization, bounded follow-up, and generation.

Evaluation

Measured quality and latency.

The advanced pipeline was compared against a naive dense baseline using the same evaluation set and Top-5 configuration.

PipelinePrecision@5Recall@5MRR
Naive dense retrieval0.8570.8570.857
Advanced FoundryRAG0.8930.9820.905
Evaluation principleAll reported results are based on measured executions and a reproducible evaluation set.
27s → 4sQuery expansion optimization.
~64 msHybrid retrieval.
~807 msCross-encoder reranking.
~6.5 sFinal local generation.
Latency trace

Stage-level latency

Every major stage is measured and displayed.

Pipeline telemetry

Pipeline telemetry

Selected context, rerank scores, filters, and source evidence are available for inspection.

Explainability

The answer is not a black box.

FoundryRAG exposes how evidence was found, ranked, reconstructed, and used.

Explainability Matrix

Shows selected nodes, node type, document, reranking score, and context membership.

Page-level inspection

Source citations open the original technical document for direct verification.

Entity graph

Technical terms and section-level relationships are visualized as a discovery layer.

System demo

A working industrial document copilot.

The interface combines knowledge-base management, technical QA, source evidence, explainability, and live telemetry.

Technical details

Architecture diagrams and project artifacts.

Explore individual processing stages, reports, evaluation assets, and roadmap.

Query processing

Query processing

Domain-agnostic rewriting and local or Azure embeddings.

Hybrid retrieval

Hybrid retrieval

BM25 and dense retrieval with Reciprocal Rank Fusion.

Context optimization

Context optimization

Reranking, grading, compression, reconstruction, and adaptive budgeting.

Adaptive retrieval

Adaptive retrieval

Confidence-based bounded multi-hop retrieval.

Answer generation

Answer generation

Grounded prompt construction, loop detection, and telemetry.

FoundryRAG

Structured retrieval, measurable behavior, and verifiable answers.

FoundryRAG moves beyond flat chunk retrieval by combining typed document structure, hybrid search, adaptive reconstruction, bounded multi-hop reasoning, source inspection, entity exploration, and cloud-ready deployment.