T-RAG: Tree-Based RAG Architecture for Question Answering Over Organizational Documents

qatar_computing_research_institute · Research & Academia · 2024 · source Agentic: no · promotional bias: low · source-backed · extracted with prompt 0.5.6 (schema v2)

Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.

Problem

Domain: Question answering over private organizational governance documents

QCRI needed reliable question answering over private governance documents for a large non-profit organization under on-premise security and limited compute constraints, while standard RAG struggled with entity hierarchies embedded in organizational structure.

Constraints:

Architecture

T-RAG combines standard retrieval with a fine-tuned Llama-2 7B model and a tree representation of organizational entities. Custom entity detection identifies relevant organizational nodes, the tree generates textual context for entity-related queries, and QLoRA fine-tuning adapts the model using generated Q&A pairs.

Diagram confidence: reconstructed (reconstructed from prose).

flowchart LR
  private_governance_documents["Private governance documents"] --> vector_retrieval["Vector retrieval"]
  private_governance_documents --> q_and_a_generation["Q&A generation"]
  organizational_entity_tree["Organizational entity tree"] --> entity_detection_pipeline["Entity detection pipeline"]
  entity_detection_pipeline --> tree_context_generator["Tree context generator"]
  vector_retrieval --> fine_tuned_llama_2_7b["Fine-tuned Llama-2 7B"]
  tree_context_generator --> fine_tuned_llama_2_7b
  q_and_a_generation --> fine_tuned_llama_2_7b
Drag to pan · scroll or use +/− to zoom · reconstructed from the source's described component topology

Components

Component Role Interacts with
Private governance documents Organizational source material used for retrieval and generated Q&A pairs. Vector retrieval, Q&A generation
Organizational entity tree Tree representation of organizational units and parent-child hierarchy. Entity detection pipeline, Tree context generator
Entity detection pipeline Uses spaCy and custom rules to detect organizational entities in questions. Organizational entity tree, Tree context generator
Vector retrieval Retrieves document chunks relevant to the question. Private governance documents, Fine-tuned Llama-2 7B
Tree context generator Turns matched entity hierarchy into textual context for the model. Entity detection pipeline, Fine-tuned Llama-2 7B
Q&A generation Generates synthetic training pairs from source documents for fine-tuning. Private governance documents, Fine-tuned Llama-2 7B
Fine-tuned Llama-2 7B On-premise answer generator adapted with QLoRA. Vector retrieval, Tree context generator, Q&A generation

Data flow

A user question is processed for organizational entities. Standard retrieval supplies document chunks, while entity detection retrieves tree context that describes parent-child organizational relationships. The fine-tuned Llama-2 7B model receives both document and tree context and generates an answer.

4 supporting quotes
“T-RAG combines Retrieval-Augmented Generation with a finetuned Llama-2 7B model and introduces a novel tree structure to represent organizational entity hierarchies”summary, stated
“The solution encodes the organizational hierarchy as a tree where each node represents an entity and parent-child relationships indicate categorical membership.”summary, stated
“The entity detection pipeline uses spaCy with custom rules for named entity recognition tailored to the organization's entities.”summary, stated
“Using QLoRA for parameter-efficient finetuning on 1,614 Q&A pairs generated from the source document, the system achieved 73% accuracy”summary, stated

Why this architecture

The tree layer was added because organizational hierarchy is central to many entity questions but is poorly represented by ordinary chunk retrieval or embeddings alone.

3 supporting quotes
“introduces a novel tree structure to represent organizational entity hierarchies, generating textual context for entity-related queries.”summary, stated
“organizational charts that don't embed well.”summary, stated
“the tree context significantly improved entity-related question accuracy”summary, stated

Models used: Llama-2 7B · QLoRA · spaCy

Scale

Alternatives considered (roads not taken)

Standard RAG

Rejected because: It underperformed T-RAG, especially on entity-related hierarchy questions.

“73% total accuracy (27/37) compared to 56.8% for standard RAG (21/37)”summary, stated

Fine-tuning alone

Rejected because: Fine-tuning alone achieved lower accuracy than tree-augmented retrieval.

“54.1% for finetuning alone (20/37).”summary, stated

Patterns

rag-retrieval (retrieval)

T-RAG augments document retrieval with tree-derived entity hierarchy context.

“T-RAG combines Retrieval-Augmented Generation with a finetuned Llama-2 7B model and introduces a novel tree structure to represent organizational entity hierarchies, generating textual context for entity-related queries.”summary, stated

fine-tuning-adaptation (model adaptation)

The team used QLoRA to adapt Llama-2 7B on generated organizational Q&A pairs.

“For the actual finetuning, they used QLoRA (Quantized Low-Rank Adaptation), which combines 4-bit quantization of model weights with LoRA for parameter-efficient finetuning.”summary, stated

synthetic-data-generation (training data)

The model generated Q&A pairs from document chunks for fine-tuning data.

“For each document chunk, the model was prompted to generate various question types (True/False, Summary, Short Answer, etc.) along with answers”summary, stated

Tradeoffs

Add tree context to RAG.

Chose Tree-RAG over Standard vector RAG.

Rationale: The tree improved hierarchy and entity-question accuracy.

“The tree context dramatically improved performance—the finetuned model without tree context answered 47.1% of simple questions correctly, while with tree context this jumped to 100%.”summary, stated

Use an on-premise fine-tuned small model.

Chose Fine-tuned Llama-2 7B with QLoRA over External hosted frontier model.

Rationale: The system had data-security and limited-compute constraints.

“data security requiring on-premise deployment, limited computational resources, and the need for reliable responses.”summary, stated

Gotchas (what bit them)

Entity hierarchy is hard for standard chunk retrieval.

Root cause: Organizational chart relationships are structural and may not be captured in embedded text chunks.

Resolution: Represent the hierarchy as a tree and inject textual tree context for entity questions.

“Standard RAG struggles with questions about entity relationships within complex hierarchies because the relevant information may be scattered across documents or represented in organizational charts that don't embed well.”summary, stated

Accuracy gains can come with verbosity.

Root cause: Tree-augmented context helped answer correctly but produced longer responses.

Resolution: Track conciseness alongside accuracy in evaluation.

“T-RAG produced more verbose responses (6 CV vs 1 for other methods), indicating a tradeoff between accuracy and conciseness.”summary, stated

Evaluation

The team compared T-RAG, standard RAG, and fine-tuning alone on answer accuracy, entity-specific tests, and Needle-in-a-Haystack robustness.

Metrics: Total accuracy. · Entity-related simple and complex question accuracy. · Needle-in-a-Haystack accuracy with 10 unrelated chunks. · Conciseness/verbosity.

“Results showed T-RAG achieved 73% total accuracy (27/37) compared to 56.8% for standard RAG (21/37) and 54.1% for finetuning alone (20/37). However, T-RAG produced more verbose responses (6 CV vs 1 for other methods), indicating a tradeoff between accuracy and conciseness.”summary, stated
“Evaluations including Needle in a Haystack tests demonstrated that the tree context significantly improved entity-related question accuracy”summary, stated

Outcomes

The case uses 1,614 generated Q&A pairs and reports evaluation over 37 total questions plus entity-specific and Needle-in-a-Haystack tests.

“Results showed T-RAG achieved 73% total accuracy (27/37) compared to 56.8% for standard RAG (21/37) and 54.1% for finetuning alone (20/37).”summary, stated
“Evaluations including Needle in a Haystack tests demonstrated that the tree context significantly improved entity-related question accuracy, with T-RAG maintaining 64.1% accuracy even with relevant context buried among 10 unrelated chunks, versus 33.3% for standard RAG.”summary, stated