Experimental, opt-in, and off by default. Truth-subspace reranking only runs
when you build the subspace and pass
use_truth_weight=True. With it off,
retrieval behaves exactly as before.session_learnings node set, Cognee builds a
small set of anchor vectors (a “truth subspace”) from those lessons, projects each
chunk onto them, and stores the resulting alignment coordinates on the graph node.
At query time the hybrid retriever reads those coordinates and nudges its chunk
ranking toward the directions the session taught it to value.
Before you start:
- Complete Quickstart and the Self-Improvement Quickstart
- Have an existing dataset and at least one session whose learnings have been distilled (via
improve()withsession_ids) - Ensure LLM Providers are configured (the build pass embeds anchors and chunks)
How It Works
The feature uses two stores with two distinct roles:| Store | What it holds | Built when | Read when |
|---|---|---|---|
TruthAnchor vector collection | one row per accepted lesson; its embedding is a truth direction | post-session build | query time → gives the query’s coordinates |
truth_alignment property on chunk nodes | each chunk’s cosine to every active anchor | post-session build | query time → gives each candidate’s coordinates |
Coordinates live on the graph node (a cheap per-property write, no re-embedding),
mirroring how
feedback_weight is stored. The reranker fetches them with a small
batched lookup for the candidate chunks only.Code in Action
Step 1: Build the truth subspace
Runimprove() with build_truth_subspace=True. After the session’s learnings are
distilled, this builds the TruthAnchor collection and writes truth_alignment
coordinates onto every chunk in the dataset.
Step 2: Retrieve with truth weighting on
Passuse_truth_weight=True through retriever_specific_config on a
HYBRID_COMPLETION search. Omit it (or set it False) for exact baseline ordering.
use_truth_weight off vs on returns the same candidates in a
different order — chunks aligned with the session’s learnings rise.
Relationship to the Feedback Loop
Truth-subspace reranking is a second, complementary signal to the Feedback System:feedback_weightis a per-element scalar learned from session ratings. It influences the graph/triplet retrievers viafeedback_influence. Activate it by settingDEFAULT_FEEDBACK_INFLUENCE(e.g.0.1); set it to0.0to restore the prior baseline.truth_alignmentis a per-chunk geometric signal learned from distilled lessons. It influences the hybrid retriever’s chunk lane viause_truth_weight.
Parameters
Parameters
improve(..., build_truth_subspace=True)— opt-in build stage. Runs after distillation; readssession_learnings, upsertsTruthAnchorrows, and writes per-chunktruth_alignmentcoordinates. DefaultFalse.search(..., retriever_specific_config={"use_truth_weight": True})— enables chunk-lane reranking forHYBRID_COMPLETION. DefaultFalse.DEFAULT_FEEDBACK_INFLUENCE(env, default0.1) — activates the separatefeedback_weightloop;0.0disables it.
Troubleshooting
Troubleshooting
- No change in ordering — confirm
build_truth_subspace=Trueran and reported a non-zero anchor / scored-node count, and that the session actually producedsession_learnings. With no anchors, reranking is a no-op. - All candidates ranked equally — the subspace only reranks the hybrid chunk lane; entity ordering is unaffected in this MVP.
- LLM/embedding errors during build — the build embeds anchors and chunk text; verify your provider is configured. See LLM Providers.
Additional Information
- A runnable end-to-end demo ships with the feature at
examples/python/truth_subspace_reranking_demo.py. It ingests a small two-theme corpus, teaches a preference via a session, builds the subspace, and prints a side-by-side rank diff so the reordering is visible.
This MVP reranks the hybrid chunk lane only and is not yet validated by an automatic
quality measurement. Keep it opt-in until you have evaluated its effect on your data.
Self-Improvement Quickstart
Bridge and enrich memory with improve()
Feedback System
The complementary per-element feedback signal
Improve
The operation that builds the subspace