Skip to content

Fix(rag) retrievers persistence signature - #1047

Open
sofiachavezb wants to merge 10 commits into
developfrom
fix(RAG)-retrievers-persistence-signature
Open

sofiachavezb wants to merge 10 commits into
developfrom
fix(RAG)-retrievers-persistence-signature

Conversation

@sofiachavezb

Copy link
Copy Markdown
Collaborator

Summary

Changing a retriever's distance metric (or its Top K) reindexed every document. Each retriever now declares which parameters only act at query time (NON_PERSISTENT_PARAMS). The identity under which a retriever is stored, looked up and cleaned up uses only the remaining parameters, resolved recursively through nested components. Top K, the similarity metric, the expansion options, batch_size and device no longer force a reindex, while the embedding pooling or the TFIDF/BM25 vectorizer still do.

Also:

  • Any change other than Top K now shows the session as an advanced configuration.
  • After every reindex, DB rows and files that no session uses are deleted.
  • Backend and frontend compare configurations with the same strict equality.

Type of Change

  • Backend change
  • Frontend change
  • CI / Workflow change
  • Build / Packaging change
  • Bug fix
  • Documentation

Changes (by file)

Persistence signature

  • models/RAG/retrievers/persistence_signature.py (new): persistence_signature and reference_signature. They drop the query-time parameters and recurse into {component, params} references and children lists. They raise if a nested component is not registered.
  • models/RAG/retrievers/base_retriever.py: NON_PERSISTENT_PARAMS on the base class and on each retriever (dense, BM25, TFIDF, composites).
  • converters/hugging_face/text_embedding/base.py: batch_size and device are non-persistent.
  • retriever_setup_service.py, index_status_service.py: the identity, the sparse folder and the rag_embedding_model row are computed from the signature.

Cleanup after reindexing

  • services/RAG/cleanup_service.py: cleanup_after_reindex and run_post_index_cleanup. They release retriever trees from parents to children (at any depth), plus the matrices, embedding models and chunk sets that no live row references. It also integrates develop's reranker cleanup and shared-bridge protection.
  • job/RAG_index_job.py: cleans up after a successful index and releases the index in a finally.
  • job/RAG_job.py: a chat turn cleans up only when the session's index changed. Composites are no longer rebuilt on every turn.
  • services/RAG/storage_layout.py (new): storage directory names, previously repeated literals.
  • services/RAG/session_params.py (new): parameter filter shared by both jobs.

Configuration equality and presets

  • services/RAG/config_equality.py and front/.../RAG/configEquality.js (new): deep structural equality that ignores key order, allows no subsets and is type-strict (a boolean never equals a number, null is not absent). Both run the shared cases in tests/shared/config_equality_cases.json.
  • retriever_presets.py, chunking_presets.py: preset matching ignores only top_k. Chunking matching goes from subset to exact.
  • front/.../RAG/presetMatching.js: findMatchingPreset throws on a missing or malformed reference.
  • RAGConfigPanel.jsx, PromptFieldCard.jsx, QueryTransformationAdvancedModal.jsx: deepEqual replaces every JSON.stringify used for comparison.
  • endpoints/rag.py: 404 when the session does not exist, 422 when stored data is malformed.

Merge with develop

  • CompositeRetrieverBuilder.jsx: keeps develop's version. The translated component names in the captions were restored.

Testing (optional)

  • uv run pytest tests/back/RAG tests/back/services: 2064 passed, 1 skipped.
  • Jest over the RAG and configurableObject suites, plus yarn build.
  • On Windows, a document-upload test can fail at random with PermissionError WinError 5 when renaming folders under tmp/documents. It passes when rerun in isolation.

Notes (optional)

  • Sessions and rows stored before this change with batch_size/device no longer match the new signature. Each dense session reindexes once and creates a new row. Old rows and matrices are reclaimed when that session is reindexed. There is no global sweep.
  • With strict equality, an old session with extra chunking or retriever parameters is now shown as "advanced". This is accepted as long as the user can keep chatting with it.
  • Number inputs still accept non-finite values. Rejecting them in NumberInput/IntegerInput is out of scope here.
  • There are no locks between concurrent jobs. A cleanup could release an embedding model that another job has resolved but not yet referenced.
  • E5MistralGGUFEmbedding inherits the device exclusion. Reusing vectors between CPU and GPU is an approximation.
  • Minor follow-ups left open:
    • Silent fallbacks for chunk_size, context_window and max_tokens.
    • _reranker_reference returns {} when query_transformation has no params.
    • has_stale_index_rows reads the child-link table of the whole database.

Add NON_PERSISTENT_PARAMS to the retriever classes and a persistence
signature that drops them, recursively, from a configuration. Query-time
knobs such as top_k, the similarity metric, the retrieve-then-expand
options or a composite's merge strategy no longer take part in the
identity of a fitted retriever.
…e signature

Setup, cleanup and index status now compare retrievers by their
persistence signature instead of ad-hoc stripping of top_k and the
similarity function. Tuning a query-time parameter, at any nesting level,
keeps the fitted state instead of deleting or re-indexing it. CleanupService
receives the component registry to resolve nested component classes.
…ration

Preset matching now ignores only top_k, at every level of the config, so
changing the similarity metric, the expansion options or batch_size shows
the session as an advanced configuration. Legacy sessions without the
expansion fields are compared strictly and may become advanced.

batch_size is declared as a non-persistent parameter of the text embedding
converters, and the embedding model row is keyed by its persistence
signature, so changing it no longer creates a new embedding model and
re-embeds every document.
Add configs_equal: deep, key-order independent, type strict (a boolean never equals a number, null is not absent), no subsets, explicit ignored keys. Preset matching, the index status and the session parameter history use it. Chunking presets now match exactly.
…lity

Replace the JSON.stringify comparisons with deepEqual, ignore only top_k when matching retriever presets, and throw on a missing or malformed reference. Shares its test cases with the backend.
device joins batch_size as a non-persistent parameter of text embedding converters, so changing it neither reindexes nor creates another embedding model row.
After a successful index job, delete the chunk sets, retriever rows, embedding models, matrices and sparse folders no session uses, walking the retriever tree from parents to children. Chat turns clean only when the index footprint changed. Storage directory names move to storage_layout.
# Conflicts:
#	DashAI/back/job/RAG_index_job.py
#	DashAI/back/services/RAG/cleanup_service.py
#	DashAI/back/services/RAG/session_configuration_service.py
#	DashAI/front/src/components/generative/RAG/RAGConfigPanel.test.jsx
#	DashAI/front/src/pages/generative/RAGSession/advanced/CompositeRetrieverBuilder.jsx
#	DashAI/front/src/pages/generative/RAGSession/advanced/QueryTransformationAdvancedModal.jsx
#	tests/back/RAG/test_cleanup_session_scope.py
@sofiachavezb
sofiachavezb added this pull request to stack #1048 November 27, 2026 00:11
Base automatically changed from fix(RAG)-similarity-metric-as-component to develop November 27, 2026 14:06
The startup backfill that translates retrievers stored by v0.11.0 completes
every level of a composite with its schema defaults, so converted hybrid
sessions store enable_retrieve_then_expand and expand_window in each child.
The hybrid preset was completed only at the top level, and with the strict
preset match every upgraded hybrid session showed as a custom configuration.
The preset now completes its children too; new sessions still round-trip.

This branch has not been deployed

No deployments
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