[AP0] Retrieval intelligence, embeddings, source-aware KB, and RLM integration #452
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
nsaspy/prolog-rlm#452
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Priority
AP0 — next coding move.
This epic captures the complete design discussed for making
prolog-rlmsmarter as a reusable library for building LLM harnesses, while preserving the existing default/reference RLM runtime.This work is ADARD, human-gated. Do not silently advance through the full implementation/merge loop.
Human-gated ADARD contract
Use distinct fresh reasoning phases and preserve evidence/decisions between them:
If implementation uncovers a material architecture change, return to the human decision gate.
0. Architectural thesis / non-negotiables
prolog-rlmis a reusable Prolog library/runtime substrate for writing harnesses. It may ship a default/reference RLM harness, CLI, agent runtime, graph runtime, prompt compiler, etc., but new work must remain composable and reusable by other harnesses.Think:
Do not turn the library into a required daemon. Do not require a filesystem watcher. Do not bake one application persona/workflow into core primitives.
The model may request standard structured actions/tool calls, but Prolog/runtime code owns dispatch, capabilities, budgets, validation, state, and execution. Final model prose does not need to be structured.
1. Reuse existing provider layer
Do not duplicate model/provider plumbing in downstream harnesses.
Reuse and extend
rlm_chainconventions:Credentials remain referenced indirectly (for example
env('OPENROUTER_API_KEY')) and are resolved at execution time. A host/editor may set that environment variable from its own config file, but raw secrets must not leak into provider terms, traces, errors, fixtures, or logs.2. Provider-neutral embeddings
Add a first-class embedding abstraction separate from chat-completion models.
API direction (exact naming/arity should follow repo conventions):
Requirements:
3. Generic
rlm_retrievallibraryAdd backend-neutral retrieval infrastructure. Keep it deliberately dumb and reusable.
Conceptual surface:
Support normalized capabilities/strategies for:
Do not make Chroma semantics the generic retrieval API.
4. Basic Chroma adapter
Add
rlm_chroma(or equivalent) on top ofrlm_retrieval.First useful slice:
Chroma is one adapter, not the architecture.
5.
retrieval_expert: symbolic/non-LLM retrieval intelligenceBuild a separate reusable expert-system layer on top of
rlm_retrievalandrlm_embedding.This is intentionally classic/symbolic AI driving modern generative AI. It must be able to make useful retrieval decisions without calling an LLM.
Conceptual API:
Initial intelligence should support extensible rules/facts for:
exact,lexical,vector,graph,structural,hybrid;Embeddings are a sensor, not the decision-maker.
Example intent:
The expert should be inspectable/explainable and reusable by arbitrary harnesses.
6. Existing source parsing / project-KB plan is part of this epic
Integrate with the existing Project/source work rather than creating a parallel code-index system.
Existing dependency chain:
Preserve the existing layering:
For Prolog source, keep SWI-native semantic analysis where it is stronger than Tree-sitter.
The project KB must remain useful independently of any coding agent or LLM.
7. Source-KB freshness is a hard correctness invariant
A served source-derived KB fact must never silently appear current when it was derived from different source bytes.
Every material source-derived fact must resolve to provenance including at least:
Current-vs-stale state must be explicit.
Do not rely on mtimes alone. Exact bytes/hash are authoritative.
8. No required watcher: lazy freshness is baked into access/loop boundaries
A filesystem watcher may exist only as an optional host hint interface. Correctness must not require a running background process.
Authoritative model:
Possible abstraction:
Do not re-hash the entire repository on every tiny predicate call. Validate at meaningful acquisition/retrieval/RLM-loop boundaries, cache within a coherent snapshot, and narrow work to relevant/dirty files where safely known.
Optional host hint:
A watcher, Emacs, IDE, Git integration, etc. may call that. It is an optimization only.
9. Harness-owned writes update the KB directly
When a Prolog-RLM tool/harness writes or patches source, the runtime already knows what changed. Exploit that immediately rather than waiting for later rediscovery.
Conceptual flow:
Conceptual API direction:
Do not couple this to one particular file-writing tool. Define a reusable source-update boundary that canonical effectful write tools can call.
10. Multiple writes must be coalesced
Do not thrash parsing/indexing for every intermediate write when several writes occur in one logical tool/agent/RLM step.
Maintain a bounded dirty-set/edit journal:
Conceptual behavior:
Intermediate half-written source must not become a supposedly complete current KB generation.
11. Multiple programs/editors and concurrent writers
A file being open in multiple programs is normal. No open handle implies ownership.
Use optimistic concurrency and exact-byte validation.
For indexing/publication:
For harness writes, use expected-hash/generation semantics where possible:
If another program changed the file between read and write, return a structured conflict rather than clobbering or publishing a KB based on stale assumptions.
Concurrent source publication must serialize/linearize per relevant Project/File generation and never expose mixed generations as one complete current snapshot.
12. Coherent snapshot semantics
RLM/retrieval consumers should query a coherent project/source snapshot rather than observe a mixture of:
Provide a snapshot identity/reference and make current queries bind to it where appropriate.
Conceptual direction:
Publishing a new generation must be atomic at the defined visibility boundary. Reindexing/error/partial states must never masquerade as complete current evidence.
13. RLM integration: two entry points
Retrieval/source knowledge must plug into the existing RLM as a library capability, not become a second orchestration system.
A. Initial context acquisition
Before the planner/model receives project evidence:
This should compose with the existing context-budget/prompt-compiler machinery.
B. Retrieval during recursive execution
A running RLM/subagent must be able to request more evidence through the normal typed/tool execution boundary.
Conceptual operation/tool:
The model expresses an information need;
retrieval_expertdecides how to satisfy it using exact/lexical/vector/graph/source retrieval. Model output does not bypass retrieval policy or source-freshness guarantees.Do not invent an incompatible proprietary model protocol if standard tool/function-calling + internal Prolog terms already suffice.
14. Prompt/tool boundary
Keep the existing distinction clear:
The library supplies prompting/selection/runtime mechanics; individual harnesses own their domain persona, goals, project workflow, and application-level instructions.
15. Testing / acceptance
At minimum, the eventual implementation path must prove:
Embeddings/retrieval
Source knowledge
Regression
rlm_chain,rlm_context,rlm_tool,rlm_agent,rlm_graph, prompt compiler, MCP, trace, and source APIs remain usable independently;dlopenauthority;16. First coding move after human design approval
Do not try to land the entire epic in one PR.
During ADARD design, identify the smallest dependency-correct vertical slice. Strong candidate ordering to evaluate:
rlm_context/RLM retrieval path;The ADARD design/adversarial phases may reorder these if repository dependencies prove a different smallest safe slice.
Human approval is required before realization and again before merge.
Refs: #93 #94 #95 #96 #97 #98 #99 and existing provider/context/tool/agent/graph/prompt compiler work.
nsaspy referenced this issue2026-09-10 21:20:52 +00:00
Duplicate of #219 (pre-existing Forgejo mirror). Closing this accidental duplicate created by today's open-state sync; #219 stays canonical on Forgejo.