Skip to content

feat: GraphRAG retrieval + context/citation engine (P13d-1)#144

Merged
blokzdev merged 1 commit into
mainfrom
claude/p13d1-rag-retrieval
Jun 3, 2026
Merged

feat: GraphRAG retrieval + context/citation engine (P13d-1)#144
blokzdev merged 1 commit into
mainfrom
claude/p13d1-rag-retrieval

Conversation

@blokzdev
Copy link
Copy Markdown
Owner

@blokzdev blokzdev commented Jun 3, 2026

P13d-1 — Local GraphRAG "Ask your library" · retrieval engine

The first slice of the flagship P13d ("Ask your library"): the pure-Dart retrieval + context/citation engine the multi-turn chat (d-2) will drive. No UI, no schema, no deps — fully CI-verifiable.

What it does

Reuses the P10 semantic substrate (embedderEngine.embedGraphQueryService.vectorSearch) plus a light relatedTo graph re-rank to gather the most relevant library items for a question, then assembles a bounded, cited context block + a history-aware generation prompt.

New — lib/features/ai/data/

  • rag_context.dart (pure)RagSource / RagChatTurn / RagContext, kRagSystemPrompt (answer ONLY from numbered sources, cite [n], say "I don't know", never invent), buildSourceSnippet (prefers aiSummary over description, capped), selectRagSources (dedupe/cap), fitHistory (recent-turn char budget — the tier-aware history-depth knob), buildRagPrompt (numbered cited sources + optional bounded history).
  • rag_availability.dart (pure)RagAvailability {unavailable, retrievalOnly, full} + ragAvailability(...), the d-3 fallback gate.
  • rag_retriever.dartRagRetriever + provider: embed query → vectorSearchrelatedTo re-rank → hydrate via MetadataRepository → cited RagContext; returns empty-sources when retrieval isn't ready (no embedder / empty index) so the caller can fall back gracefully.

Decomposition (revised — multi-turn chat)

The P13d card is rewritten to the maintainer-approved multi-turn target: persistent conversations on capable tiers (list / continue / rename / archive / delete), each turn re-retrieving fresh sources + a bounded history window whose depth scales with the device tier; retrieval-only fallback on low / ineligible tiers; entry from the Dashboard.

  • d-1 (this PR): retrieval + context/citation + history-aware prompt builder.
  • d-2a: chat schema + Ask screen (single conversation, streaming grounded answer + citations).
  • d-2b: conversation list + manage.
  • d-3: low-tier retrieval-only fallback + tier-aware depth + LLM/HNSW RAM co-residency validation.

Tests

rag_context_test.dart (prompt numbering / question / history fold + budget truncation, fitHistory, selectRagSources, buildSourceSnippet), rag_availability_test.dart (truth table), rag_retriever_test.dart (fake embedder + graph + seeded in-memory metadata → ordered cited sources + grounded prompt; empty/unready → no sources).

Docs

docs/design/P13-PLAN.md (P13d card → multi-turn decomposition; d-1 [~]), docs/VERIFICATION.md (P13d-1 is the CI-covered engine; end-to-end ask flow verified at d-2), docs/BACKLOG.md (retrieval-only-answer persistence, per-tier history budget, RAM co-residency — carried to d-3).

Verification

dart format · flutter analyze · flutter test — all green (839 tests). No APK check: d-1 ships no user-facing UI (it's d-2's engine).

https://claude.ai/code/session_013JoYmLCosYt5tQ8qwdbL1T


Generated by Claude Code

The pure-Dart retrieval core for the local "Ask your library" GraphRAG
chat (P13d): reuse the P10 semantic substrate (embed -> vector search)
plus a light graph re-rank to gather the most relevant library items for
a question, then assemble a bounded, cited context block + a
history-aware generation prompt the chat (d-2) will drive.

New lib/features/ai/data/:
- rag_context.dart (pure): RagSource/RagChatTurn/RagContext,
  kRagSystemPrompt, buildSourceSnippet (aiSummary>description, capped),
  selectRagSources (dedupe/cap), fitHistory (recent-turn char budget --
  the tier-aware history-depth knob), buildRagPrompt (numbered cited
  sources + optional bounded history).
- rag_availability.dart (pure): RagAvailability {unavailable,
  retrievalOnly, full} + ragAvailability(...) -- the d-3 fallback gate.
- rag_retriever.dart: RagRetriever + provider -- embed query ->
  vectorSearch -> relatedTo re-rank -> hydrate via MetadataRepository ->
  cited RagContext; empty-sources when retrieval isn't ready.

Tests: prompt/snippet/fitHistory/selectRagSources, the ragAvailability
truth table, and the retriever with fake embedder + graph + seeded
in-memory metadata. No deps, no schema, no UI (it's d-2's engine).

Docs: P13-PLAN.md P13d card rewritten to the multi-turn decomposition
(d-1/d-2a/d-2b/d-3) + d-1 [~]; VERIFICATION.md P13d-1 note; BACKLOG.md
retrieval-only persistence, per-tier history budget, RAM co-residency.

https://claude.ai/code/session_013JoYmLCosYt5tQ8qwdbL1T
@blokzdev blokzdev merged commit 0e1bb5d into main Jun 3, 2026
1 check passed
@blokzdev blokzdev deleted the claude/p13d1-rag-retrieval branch June 3, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants