Skip to content

Commit 38deee7

Browse files
committed
refactor(rag): separate document retrieval from preprocessing
1 parent c5eaf8f commit 38deee7

27 files changed

Lines changed: 356 additions & 237 deletions

File tree

.agents/skills/quantmind-dev/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: quantmind-dev
3-
description: Contributor workflow for the QuantMind codebase. Covers commit format, pull request format, and component development across quantmind/ modules (knowledge, configs, preprocess, flows, mind, utils) with tests, examples, and verification. Use when committing, opening a PR, or implementing/refactoring QuantMind code.
3+
description: Contributor workflow for the QuantMind codebase. Covers commit format, pull request format, and component development across quantmind/ modules (knowledge, configs, preprocess, rag, flows, mind, utils) with tests, examples, and verification. Use when committing, opening a PR, or implementing/refactoring QuantMind code.
44
---
55

66
# QuantMind Dev

.agents/skills/quantmind-dev/references/develop-components.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ apply throughout.
3535
| `quantmind/knowledge/` | nothing (leaf) |
3636
| `quantmind/configs/` | `knowledge` only |
3737
| `quantmind/preprocess/` | `utils` only |
38+
| `quantmind/rag/` | `preprocess` only |
3839
| `quantmind/flows/`, `quantmind/magic.py` | apex — may import all of the above |
3940

4041
### `quantmind/knowledge/` — data standard
@@ -60,6 +61,16 @@ apply throughout.
6061
- Surface the common path at the package root (`from quantmind.preprocess
6162
import fetch_arxiv`), keep explicit submodule paths working.
6263

64+
### `quantmind/rag/` — opinionated document RAG
65+
66+
- Use LlamaIndex for chunking, indexing, retrieval, and ranking; add only the
67+
source/page/provenance conversion that QuantMind owns.
68+
- Import deterministic inputs from `quantmind.preprocess`; preprocessing must
69+
never import RAG.
70+
- Keep LlamaIndex types private. Return frozen QuantMind evidence values.
71+
- Do not add a public retriever, vector-store, provider, backend registry, or
72+
generic query-engine hierarchy.
73+
6374
### `quantmind/flows/` and `quantmind/magic.py` — apex layer
6475

6576
- Public operations are `async def` functions, not classes; state passes

.claude/skills/quantmind-dev/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
name: quantmind-dev
3-
description: Contributor workflow for the QuantMind codebase. Covers commit format, pull request format, and component development across quantmind/ modules (knowledge, configs, preprocess, flows, mind, utils) with tests, examples, and verification. Use when committing, opening a PR, or implementing/refactoring QuantMind code.
3+
description: Contributor workflow for the QuantMind codebase. Covers commit format, pull request format, and component development across quantmind/ modules (knowledge, configs, preprocess, rag, flows, mind, utils) with tests, examples, and verification. Use when committing, opening a PR, or implementing/refactoring QuantMind code.
44
---
55

66
# QuantMind Dev

.claude/skills/quantmind-dev/references/develop-components.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ apply throughout.
3535
| `quantmind/knowledge/` | nothing (leaf) |
3636
| `quantmind/configs/` | `knowledge` only |
3737
| `quantmind/preprocess/` | `utils` only |
38+
| `quantmind/rag/` | `preprocess` only |
3839
| `quantmind/flows/`, `quantmind/magic.py` | apex — may import all of the above |
3940

4041
### `quantmind/knowledge/` — data standard
@@ -60,6 +61,16 @@ apply throughout.
6061
- Surface the common path at the package root (`from quantmind.preprocess
6162
import fetch_arxiv`), keep explicit submodule paths working.
6263

64+
### `quantmind/rag/` — opinionated document RAG
65+
66+
- Use LlamaIndex for chunking, indexing, retrieval, and ranking; add only the
67+
source/page/provenance conversion that QuantMind owns.
68+
- Import deterministic inputs from `quantmind.preprocess`; preprocessing must
69+
never import RAG.
70+
- Keep LlamaIndex types private. Return frozen QuantMind evidence values.
71+
- Do not add a public retriever, vector-store, provider, backend registry, or
72+
generic query-engine hierarchy.
73+
6374
### `quantmind/flows/` and `quantmind/magic.py` — apex layer
6475

6576
- Public operations are `async def` functions, not classes; state passes

.github/workflows/e2e.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ on:
1818
- 'quantmind/preprocess/fetch/rss.py'
1919
- 'quantmind/preprocess/fetch/arxiv.py'
2020
- 'quantmind/preprocess/format/pdf.py'
21+
- 'quantmind/rag/**'
2122
- 'scripts/verify_pdf_rag_e2e.py'
2223
- 'pyproject.toml'
2324
schedule:
@@ -64,6 +65,7 @@ jobs:
6465
- 'scripts/verify_pdf_rag_e2e.py'
6566
- 'quantmind/preprocess/fetch/arxiv.py'
6667
- 'quantmind/preprocess/format/pdf.py'
68+
- 'quantmind/rag/**'
6769
- 'pyproject.toml'
6870
6971
news:

AGENTS.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ handoff all come from `openai-agents`.
3636
| `quantmind/library/` | Local persistence and semantic retrieval for canonical knowledge — depends only on `knowledge` |
3737
| `quantmind/configs/` | Operation cfg + typed input models or unions (`BaseFlowCfg`, `NewsWindow`, `PaperInput`) — depends only on `knowledge` |
3838
| `quantmind/preprocess/` | Deterministic fetch / format / clean / time utilities — depends only on `utils` |
39+
| `quantmind/rag/` | Opinionated LlamaIndex document chunking and retrieval — depends only on `preprocess` |
3940
| `quantmind/flows/` | Apex layer: public library operations (`paper_flow`, `collect_news`, `batch_run`) |
4041
| `quantmind/magic.py` | `resolve_magic_input`: natural language → `(input, cfg)` |
4142
| `quantmind/mind/` | Cognitive layer (memory protocol); landing via the Agents SDK migration (#71) |
@@ -75,19 +76,22 @@ the user explicitly authorizes it — fix the underlying issue instead.
7576

7677
1. **Library, not framework** — functions over classes, `Protocol` over ABC,
7778
no plugin registries, no hook discovery, no CLI.
78-
2. **Do not rebuild the agent runtime** — use `openai-agents` directly; no
79+
2. **RAG data plane, not framework** — use LlamaIndex directly inside
80+
`quantmind.rag`; keep upstream types private and do not add retriever,
81+
vector-store, provider, or backend registries.
82+
3. **Do not rebuild the agent runtime** — use `openai-agents` directly; no
7983
QuantMind-side facades over `from agents import ...`.
80-
3. **Schema models vs runtime evidence** — user/LLM inputs and configs use
84+
4. **Schema models vs runtime evidence** — user/LLM inputs and configs use
8185
extra-forbid Pydantic models; knowledge adds `frozen=True`; deterministic
8286
fetch, preprocessing, and collection values use frozen dataclasses when
8387
they do not need validation or JSON Schema (`Fetched`, `NewsBatch`).
84-
4. **Import boundaries are contracts**`import-linter` (configured in
88+
5. **Import boundaries are contracts**`import-linter` (configured in
8589
`pyproject.toml`) pins the dependency graph; never work around a failing
8690
contract.
87-
5. **Absolute imports** across module boundaries.
88-
6. **No meaningless wrappers** — a method must add logic, abstraction, or a
91+
6. **Absolute imports** across module boundaries.
92+
7. **No meaningless wrappers** — a method must add logic, abstraction, or a
8993
side effect beyond the call it wraps; otherwise inline it.
90-
7. **Name public operations by intent** — follow
94+
8. **Name public operations by intent** — follow
9195
`contexts/design/operations/naming.md`; use stage verbs, and reserve
9296
`pipeline` for deliberate multi-stage composition.
9397

CLAUDE.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ handoff all come from `openai-agents`.
3737
| `quantmind/library/` | Local persistence and semantic retrieval for canonical knowledge — depends only on `knowledge` |
3838
| `quantmind/configs/` | Operation cfg + typed input models or unions (`BaseFlowCfg`, `NewsWindow`, `PaperInput`) — depends only on `knowledge` |
3939
| `quantmind/preprocess/` | Deterministic fetch / format / clean / time utilities — depends only on `utils` |
40+
| `quantmind/rag/` | Opinionated LlamaIndex document chunking and retrieval — depends only on `preprocess` |
4041
| `quantmind/flows/` | Apex layer: public library operations (`paper_flow`, `collect_news`, `batch_run`) |
4142
| `quantmind/magic.py` | `resolve_magic_input`: natural language → `(input, cfg)` |
4243
| `quantmind/mind/` | Cognitive layer (memory protocol); landing via the Agents SDK migration (#71) |
@@ -76,19 +77,22 @@ the user explicitly authorizes it — fix the underlying issue instead.
7677

7778
1. **Library, not framework** — functions over classes, `Protocol` over ABC,
7879
no plugin registries, no hook discovery, no CLI.
79-
2. **Do not rebuild the agent runtime** — use `openai-agents` directly; no
80+
2. **RAG data plane, not framework** — use LlamaIndex directly inside
81+
`quantmind.rag`; keep upstream types private and do not add retriever,
82+
vector-store, provider, or backend registries.
83+
3. **Do not rebuild the agent runtime** — use `openai-agents` directly; no
8084
QuantMind-side facades over `from agents import ...`.
81-
3. **Schema models vs runtime evidence** — user/LLM inputs and configs use
85+
4. **Schema models vs runtime evidence** — user/LLM inputs and configs use
8286
extra-forbid Pydantic models; knowledge adds `frozen=True`; deterministic
8387
fetch, preprocessing, and collection values use frozen dataclasses when
8488
they do not need validation or JSON Schema (`Fetched`, `NewsBatch`).
85-
4. **Import boundaries are contracts**`import-linter` (configured in
89+
5. **Import boundaries are contracts**`import-linter` (configured in
8690
`pyproject.toml`) pins the dependency graph; never work around a failing
8791
contract.
88-
5. **Absolute imports** across module boundaries.
89-
6. **No meaningless wrappers** — a method must add logic, abstraction, or a
92+
6. **Absolute imports** across module boundaries.
93+
7. **No meaningless wrappers** — a method must add logic, abstraction, or a
9094
side effect beyond the call it wraps; otherwise inline it.
91-
7. **Name public operations by intent** — follow
95+
8. **Name public operations by intent** — follow
9296
`contexts/design/operations/naming.md`; use stage verbs, and reserve
9397
`pipeline` for deliberate multi-stage composition.
9498

contexts/design/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ implementation must preserve.
2727
| Flow | [Paper extraction from input to validated result](flow/paper.md) |
2828
| Flow | [News collection](flow/news.md) |
2929
| Preprocess | [Page-aware multimodal PDF parsing](preprocess/pdf.md) |
30+
| RAG | [Page-aware document chunking and retrieval](rag/document.md) |
3031
| Library | [Local knowledge storage and meaning-based search](library/local.md) |
3132
| Operations | [Public operation naming](operations/naming.md) |
3233

contexts/design/flow/paper.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
- **Purpose**: Define how a paper input becomes a validated `Paper`.
66
- **Read when**: Changing paper inputs, parsing, section trees, source tracking, page ranges, or future PageIndex support.
7-
- **Status**: Mixed. Page-aware PDF parsing and LlamaIndex ingestion are implemented; [Current Gaps](#current-gaps) lists the remaining paper assembly work.
7+
- **Status**: Mixed. Page-aware PDF parsing and document RAG are implemented; [Current Gaps](#current-gaps) lists the remaining paper assembly work.
88
- **Core rule**: A model or PageIndex may suggest a section tree. Code creates the final IDs, links, order, page ranges, citations, and source-backed text.
99
- **Page numbering**: PDF page ranges start at 1 and include both the first and last page.
1010

@@ -57,6 +57,7 @@ across them, or write answers.
5757
| Work | Owner |
5858
|---|---|
5959
| Resolve identifiers, fetch bytes, parse pages, and hash source content | `quantmind.preprocess` |
60+
| Chunk or retrieve page-aware document evidence when requested | `quantmind.rag` |
6061
| Configure the operation and select the input variant | `quantmind.configs` |
6162
| Suggest a section tree and build the final `Paper` | `quantmind.flows` |
6263
| Define the `Paper`, `TreeKnowledge`, `TreeNode`, source, citation, and extraction models | `quantmind.knowledge` |
@@ -309,6 +310,10 @@ Future integration must preserve these decisions:
309310
6. Sibling page ranges may overlap, and a child range does not need to fit
310311
completely inside its parent range.
311312

313+
A PageIndex adapter belongs with other opinionated document retrieval in
314+
[`quantmind.rag`](../rag/document.md). It still returns the limited draft above;
315+
it does not become the canonical tree or a generic retrieval backend.
316+
312317
## Fixed Paper Test Data
313318

314319
The fixed test files live at:
@@ -336,8 +341,8 @@ The repository does not yet guarantee the target pipeline above:
336341

337342
- `pdf_to_markdown()` remains a compatibility view, while the primary
338343
`parse_pdf()` path now preserves pages, blocks, coordinates, and artifacts.
339-
- `paper_flow()` has not yet adopted `ParsedDocument`; it still consumes the
340-
compatibility Markdown view.
344+
- `paper_flow()` has not yet adopted `ParsedDocument` or the document RAG
345+
boundary; it still consumes the compatibility Markdown view.
341346
- `paper_flow()` sends the flattened document to one extraction agent and asks
342347
it to return the final `Paper` directly.
343348
- The model currently controls IDs, edges, citations, source fields, and

contexts/design/library/local.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ implementation proves which behavior is truly shared.
4242
|---|---|
4343
| `quantmind.knowledge` | Define immutable knowledge models and the text used for embeddings; perform no I/O |
4444
| `quantmind.library` | Store validated knowledge, maintain rebuildable search records, and return `SemanticHit` results |
45+
| [`quantmind.rag`](../rag/document.md) | Chunk and retrieve evidence within one parsed document without storing canonical knowledge |
4546
| `quantmind.flows` | Produce validated knowledge and optionally pass it to a library |
4647
| `quantmind.mind` or an agent application | Search the library and use matches to write answers |
4748
| Caller or source-specific pipeline | Retain raw PDF, HTML, media, and operational files |
@@ -127,7 +128,8 @@ retrieval capabilities; it is not defined as a vector database. A future
127128
PageIndex path can select a paper through collection-wide semantic retrieval,
128129
then navigate that selected document's tree through a separate operation and
129130
separately rebuildable state. PageIndex does not have to be served through
130-
`search()` or LlamaIndex ranking.
131+
`search()` or LlamaIndex ranking. Opinionated document retrieval, including a
132+
future PageIndex adapter, belongs under [`quantmind.rag`](../rag/document.md).
131133

132134
## Out of Scope
133135

0 commit comments

Comments
 (0)