-
Notifications
You must be signed in to change notification settings - Fork 7
feat(rag): add a real reranker to RAG retrieval #911
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
OchnikBartek
wants to merge
46
commits into
main
Choose a base branch
from
feat/rag-reranker
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 41 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
1292250
feat(budget): book a pre-priced entry to the active ledger
OchnikBartek 6e02b1d
feat(rag): add rerank columns to knowledge_bases
OchnikBartek 63cf6f6
feat(rag): resolve a collection's reranker and whose key pays
OchnikBartek 5258ec2
feat(rag): add BaseReranker and a Cohere implementation
OchnikBartek d88b8aa
feat(rag): rerank retrieval candidates when a collection is configured
OchnikBartek 8dd6ca8
feat(rag): meter POST /rag/search against the organization
OchnikBartek 22a2395
feat(rag): let a knowledge base set its reranker
OchnikBartek 3e2bedf
test(rag): pin the rerank key never escapes and stays in its tenant
OchnikBartek 217eaed
docs(rag): document per-collection reranking
OchnikBartek bf12b00
feat(rag): set a collection's reranker from the KB create dialog
OchnikBartek b2a84a0
fix(rag): reuse the existing cohere purpose instead of duplicating it
OchnikBartek 72e0744
fix(rag): rerank on the agent-run path, not only /rag/search
OchnikBartek a1ced17
docs(rag): state the first-collection rerank rule and the min_score s…
OchnikBartek d97c2bb
feat(rag): edit or turn off a collection's reranker after creation
OchnikBartek 117e8f7
fix(rag): check the caller may use a rerank key before binding it
OchnikBartek b3bf3b1
fix(rag): warn when a deleted key leaves a half-configured reranker
OchnikBartek 81b6072
fix(rag): book a failed search's spend before its transaction rolls back
OchnikBartek 0249a3f
fix(rag): don't offer a reranking edit on an app-scoped collection
OchnikBartek 79247fe
test(e2e): scope the ingestion Edit click past the new reranking panel
OchnikBartek 345bdfd
Merge branch 'main' into feat/rag-reranker
OchnikBartek 311fe07
merge: bring feat/rag-reranker up to date with main
OchnikBartek 17008b4
fix(rag): refuse a knowledge search past the organization's budget
OchnikBartek 66907bf
fix(rag): reject an unsupported rerank model at create and update
OchnikBartek 77770f6
fix(rag): rerank a multi-collection union only when its collections a…
OchnikBartek 0be16b2
test(e2e): await the now-async howItReads before clicking its Edit
OchnikBartek 4348329
fix(rag): report search spend as retrieval, not indexing
OchnikBartek 4f48ab5
merge: reconcile with the stale remote feat/rag-reranker tip
OchnikBartek 02cf4af
Merge branch 'main' into feat/rag-reranker
OchnikBartek 9a66605
Merge branch 'main' into feat/rag-reranker
OchnikBartek 55bce96
fix(rag): re-parent rerank migrations onto main's new head
OchnikBartek 0397e86
fix(rag): close the Cohere client each rerank builds
OchnikBartek 932d501
fix(rag): scope embedding and rerank resolution to the acting tenant …
OchnikBartek 87039b7
Merge remote-tracking branch 'origin/main' into feat/rag-reranker
OchnikBartek a5f3a7c
fix(rag): renumber the rerank migrations onto main's 0045
OchnikBartek d3b2a6d
fix(rag): pass organization_id from the rag-search CLI
OchnikBartek 6ae3331
fix(rag): meter rerank by Cohere's billed search units
OchnikBartek 1ad0015
fix(vault): report knowledge-base bindings in secret usage
OchnikBartek 7c985d4
fix(rag): resolve a search's collection by the authorized knowledge base
OchnikBartek cfdc96e
test(rag): widen the reserved-names fake resolver to the new signature
OchnikBartek b869b89
Merge remote-tracking branch 'origin/main' into feat/rag-reranker
OchnikBartek 2c72d65
fix(rag): renumber the rerank migrations onto main's 0055
OchnikBartek 11c8d47
fix(rag): carry bound knowledge-base ids through agent retrieval
OchnikBartek 278b6c7
merge: bring feat/rag-reranker up to date with main
OchnikBartek 2472ff3
style(rag): wrap the reserved-names test resolver ruff-format wants b…
OchnikBartek 2dcbd86
Merge remote-tracking branch 'origin/main' into feat/rag-reranker
OchnikBartek 69e42a0
fix(rag): reparent rerank migrations onto main's 0059_invite_fk_ondelete
OchnikBartek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| """Which reranker - and whose key - a collection reranks search results with. | ||
|
|
||
| Retrieval fetches candidates by vector similarity and returns the top ones. A | ||
| reranker is a second pass: a model scores each candidate against the query | ||
| directly and reorders them, which is more accurate than the distance the vector | ||
| index sorts by. It is optional and off by default. | ||
|
|
||
| Two nullable columns, mirroring the embedding pair. `rerank_model` is the | ||
| reranker's name; `rerank_secret_id` is the organization vault key that pays for | ||
| it. Reranking runs only when *both* are set - either NULL leaves retrieval | ||
| exactly as it was, so existing rows and unconfigured deployments are unchanged | ||
| by this migration. SET NULL on delete for the same reason the embedding key is: | ||
| losing the key drops reranking, it does not take document search down. Unlike | ||
| the embedding key there is no deployment fallback - a reranker with no key is | ||
| simply off. | ||
|
|
||
| Revision ID: 0056_knowledge_base_rerank | ||
| Revises: 0055_sandbox_operations | ||
| Create Date: 2026-08-18 | ||
|
|
||
| """ | ||
|
|
||
| from collections.abc import Sequence | ||
|
|
||
| import sqlalchemy as sa | ||
|
|
||
| from alembic import op | ||
|
|
||
| revision: str = "0056_knowledge_base_rerank" | ||
| down_revision: str | None = "0055_sandbox_operations" | ||
|
github-code-quality[bot] marked this conversation as resolved.
Fixed
|
||
| branch_labels: str | Sequence[str] | None = None | ||
| depends_on: str | Sequence[str] | None = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.add_column( | ||
| "knowledge_bases", | ||
| sa.Column("rerank_model", sa.String(length=128), nullable=True), | ||
| ) | ||
| op.add_column( | ||
| "knowledge_bases", | ||
| sa.Column("rerank_secret_id", sa.UUID(), nullable=True), | ||
| ) | ||
| op.create_foreign_key( | ||
| op.f("knowledge_bases_rerank_secret_id_fkey"), | ||
| "knowledge_bases", | ||
| "organization_secrets", | ||
| ["rerank_secret_id"], | ||
| ["id"], | ||
| ondelete="SET NULL", | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_constraint( | ||
| op.f("knowledge_bases_rerank_secret_id_fkey"), | ||
| "knowledge_bases", | ||
| type_="foreignkey", | ||
| ) | ||
| op.drop_column("knowledge_bases", "rerank_secret_id") | ||
| op.drop_column("knowledge_bases", "rerank_model") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| """Tag each non-run RAG spend row as indexing or retrieval. | ||
|
|
||
| `ingestion_spend` began as indexing alone, then a metered `POST /rag/search` | ||
| landed its embedding and rerank cost in the same table - both are RAG spend | ||
| outside any agent run. Left undistinguished, a search inflated the dashboard's | ||
| "indexing" subtotal. `source` tells them apart; both still count toward the | ||
| monthly budget, only the reporting split reads the column. | ||
|
|
||
| Every row that predates the column is indexing, so `server_default` backfills | ||
| them to `'ingestion'` without a data migration. | ||
|
|
||
| Revision ID: 0057_ingestion_spend_source | ||
| Revises: 0056_knowledge_base_rerank | ||
| Create Date: 2026-08-20 | ||
|
|
||
| """ | ||
|
|
||
| from collections.abc import Sequence | ||
|
|
||
| import sqlalchemy as sa | ||
|
|
||
| from alembic import op | ||
|
|
||
| revision: str = "0057_ingestion_spend_source" | ||
|
github-code-quality[bot] marked this conversation as resolved.
Fixed
|
||
| down_revision: str | None = "0056_knowledge_base_rerank" | ||
|
github-code-quality[bot] marked this conversation as resolved.
Fixed
|
||
| branch_labels: str | Sequence[str] | None = None | ||
| depends_on: str | Sequence[str] | None = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.add_column( | ||
| "ingestion_spend", | ||
| sa.Column( | ||
| "source", | ||
| sa.String(length=16), | ||
| nullable=False, | ||
| server_default="ingestion", | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_column("ingestion_spend", "source") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.