File size: 8,841 Bytes
8cfc5e2
 
 
 
 
13784a6
f0307a2
 
 
 
 
 
13784a6
 
 
 
 
 
b0af996
 
13784a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b0af996
 
 
 
 
 
 
 
 
 
13784a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d6ee0a6
13784a6
 
 
 
d6ee0a6
 
 
f4b92b8
d6ee0a6
 
 
 
 
 
 
13784a6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27716f7
 
 
 
 
 
 
 
 
 
 
 
 
 
b0af996
 
 
 
 
 
 
 
 
03bed0b
 
 
 
f79a242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8cfc5e2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# Query planning - v2.0 final

## Final planner contract

The recommended general-purpose profile remains `Auto + Balanced`. v2.0 also aligns the multi-hop Hard Mode reference case with that semantic path so multi-source comparison is evaluated as `comparison -> hierarchical` rather than through Fast mode's intentionally cheap fallback. No phrase-specific production route was added.

## v1.9 task/strategy consistency and scale-aware retrieval

The semantic planner remains schema-constrained, but v1.9 applies structural normalization after parsing so equivalent task/strategy pairs do not drift: `overview` uses `global`, `insight_synthesis` uses `analytical`, and comparison/cross-document work cannot remain a simple semantic-only strategy. This is task-level normalization rather than phrase-specific routing.

Retrieval depth is independently scale-aware. The planner decides *what kind* of retrieval is required; the runtime decides *how many candidates* are needed for the current corpus and then chooses a smaller generation context only when the task is focused and retrieval confidence permits it.

## 1. QueryPlan

Balanced and Agentic requests begin with a schema-constrained semantic analysis step. The plan contains:

- `route`: documents / web / hybrid / sql
- `knowledge_scope`: corpus / external / mixed / structured_data
- `task_type`: fact_lookup / overview / cross_document_synthesis / comparison / aggregation / insight_synthesis / followup
- `retrieval_strategy`: semantic / global / hierarchical / analytical / table / none
- `web_relevance`: required / useful / irrelevant
- `requires_fresh_web`
- standalone `rewritten_query`
- independent `document_queries`
- independent `web_queries`
- optional HyDE passage

The planner receives a compact manifest of the currently indexed corpus. Therefore temporal adjectives are interpreted in context: “current corpus” is local session state; “current exchange rate” is external freshness.

## 2. Source profiles

At ingestion, RAGForge groups document units/chunks by source and builds a deterministic profile from:

- source name/type
- document-unit, page, section and chunk counts
- representative excerpts sampled across the source

Profiles are embedded into a second retrieval-only index. They do not become answer evidence or synthetic citations.

## 3. Retrieval strategies

### semantic
Normal dense + BM25 + RRF + optional cross-encoder reranking across chunks.

### hierarchical
1. Retrieve source profiles.
2. Select relevant sources.
3. Search chunks only inside selected sources.
4. Diversify across sources for comparison/cross-document tasks.

### global
Choose source-balanced evidence so broad corpus summaries are not dominated by a long document. When the corpus contains more sources than final `top_k`, the source-profile index selects the most relevant subset.


### analytical
Used for `insight_synthesis` questions that ask what the indexed collection reveals, which patterns/trends stand out, or what important takeaways emerge across local evidence. The pipeline combines:

1. source-balanced original document chunks;
2. deterministic DuckDB table schema, bounded rows and descriptive signals;
3. one grounded synthesis step that distinguishes observations from interpretation.

Structured evidence is exposed as `[T#]` citations. This path is intentionally different from `table`: `table` computes a specific structured answer, while `analytical` synthesizes patterns across documents and tables.

### table
Use the isolated DuckDB/Text2SQL path.

### none
Used when documents are not part of the information need.

## 4. Corrective RAG policy

The correction loop is intentionally different from “weak score → web”.

```text
retrieve

task-aware evidence grade
  ├─ sufficient → generate
  └─ weak

     correct query/strategy

     retrieve again

     re-grade
       ├─ web semantically relevant + allowed → web
       └─ web irrelevant → explicit abstain
```

The first correction can rewrite document queries and change a focused semantic strategy to hierarchical/global retrieval. It cannot convert a private corpus-only information need into an external-only task simply because retrieval was weak.


## 4.5 Workspace preflight

RAGForge v1.4 treats missing local state as a lifecycle condition rather than a retrieval score. After semantic routing:

- a document route with zero indexed chunks terminates in `abstain`;
- a table/SQL route with zero tables terminates in `abstain`;
- a hybrid route with no local corpus may preserve the external half only when web information is semantically relevant and permitted.

This prevents an empty workspace from flowing through retrieval, generation, verification and revision as if it were merely a difficult question. The public UI can separately rebuild the bundled demo corpus before the graph runs.

## 5. Evidence grading

The local evidence score uses calibrated-ish retrieval signals rather than RRF or reranker raw values:

- top dense/BM25 relevance
- mean top-3 relevance
- dense/sparse method agreement
- distinct-source coverage

Weights vary by task:

- focused facts prioritize relevance
- comparisons/cross-document synthesis increase source diversity weight
- overview/global tasks strongly prioritize source coverage

Borderline Balanced cases and Agentic cases may also use a semantic LLM evidence judge.

## 6. Web permission vs relevance

`allow_web_fallback=True` means the application *may* use web if the plan says external information is relevant. It does not force web on a low retrieval score. Explicit Web/Hybrid route selection remains an override.

## 7. Regression tests

The evaluation harness includes session-local ambiguities such as:

- “What is the corpus about?”
- “I meant the current corpus that we have — what is that about?”

The expected behavior is document routing, overview/global retrieval, broad source coverage, and no web usage. These are behavioral tests only; no application rule matches those literal phrases.

## v1.5 adaptive reranking policy

The semantic planner still decides *what* retrieval strategy is needed. A separate runtime policy decides whether the local cross-encoder is worth its CPU latency for that plan.

When the reranker switch is enabled:

- Fast profile skips the cross-encoder;
- global/source-profile overview retrieval skips it because source balancing already determines corpus breadth;
- Balanced small-corpus focused lookups can skip it when the demo ablation shows no source-ranking benefit;
- comparison/cross-document tasks can retain it;
- larger corpora and Agentic profile can retain it.

The `retrieve`/`web` trace records `reranker_used` and `reranker_reason`. The explicit Standard/Deep ablation still runs both Hybrid RRF and Hybrid + reranker so the policy remains measurable rather than assumed.

## v1.6 insight-routing rules

- “What files are here?” remains `overview -> global`.
- “What exactly does this collection reveal? What trends stand out?” becomes `insight_synthesis -> analytical`.
- “Which tier has the shortest SLA?” remains `aggregation -> table`.
- “Compare our NIST document with the latest online guidance” remains `comparison -> hierarchical` with mixed/web relevance.

The planner is explicitly told that a collection-wide insight question should stay local/analytical even when structured tables are present; the existence of a table alone does not force SQL routing.

## v1.7 grounded absence behavior

A corpus-scoped fact lookup can legitimately conclude that the indexed evidence does not state the requested fact. v1.7 treats an evidence-cited absence statement as calibrated uncertainty, not as a hallucination signal. This does not change routing to the web: web fallback still requires semantic relevance/permission. The grounded-absence state simply prevents an unnecessary answer-revision call when the model has already answered conservatively from the local evidence.

## v1.8 focused context-budget behavior

Query planning still decides task/scope/strategy before any pruning. Context budgeting is deliberately a post-retrieval optimization, not a new routing heuristic.

Eligible runtime path:

```text
corpus/hybrid local evidence
+ fact_lookup or followup
+ semantic or hierarchical retrieval
+ context pruning enabled
-> keep top 3 ranked chunks
```

Ineligible tasks keep full breadth:

```text
overview
insight_synthesis
comparison
cross_document_synthesis
analytical/global retrieval
```

This separation prevents a latency optimization from silently redefining the user's information need. For focused fact lookups, generation also omits the full corpus manifest because the planner has already established corpus scope; broad and mixed tasks retain it.