Skip to content

Commit dbe794a

Browse files
committed
Defensive publication: hybrid-rag-ranking-graceful-fallback (public prior art, 2026-06-25)
0 parents  commit dbe794a

14 files changed

Lines changed: 2479 additions & 0 deletions

.gitignore

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Node
2+
node_modules/
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
pnpm-debug.log*
7+
.npm/
8+
.pnp.*
9+
.yarn/
10+
11+
# Build / coverage
12+
dist/
13+
build/
14+
coverage/
15+
*.tsbuildinfo
16+
17+
# Env / secrets (never commit)
18+
.env
19+
.env.*
20+
*.pem
21+
*.key
22+
23+
# Editor / OS
24+
.vscode/
25+
.idea/
26+
.DS_Store
27+
Thumbs.db
28+
*.swp
29+
*.log

CITATION.cff

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
cff-version: 1.2.0
2+
message: "If you reference this defensive publication, please cite it as below."
3+
title: "Hybrid RAG Ranking with Graceful LLM Fallback"
4+
abstract: >-
5+
A technical defensive publication describing a two-stage retrieval ranker in
6+
which a deterministic, always-available lexical stage (TF-IDF-style scoring with
7+
title and recency boosts) owns the critical path, and an optional language-model
8+
re-ranking stage — bounded to a top-K subset and governed by a pre-call budget
9+
and an explicit deadline — runs off the critical path and fails open to the
10+
deterministic result on any timeout, error, malformed output, invalid permutation,
11+
or budget breach, without surfacing that failure to the caller. Published as prior
12+
art to keep the technique freely practiceable and unpatentable by others.
13+
type: report
14+
authors:
15+
- family-names: "Assuncao"
16+
given-names: "Gustavo"
17+
affiliation: "Gus IT LLC (Florida, USA)"
18+
version: "1.0"
19+
date-released: "2026-06-25"
20+
license: AGPL-3.0-or-later
21+
keywords:
22+
- defensive-publication
23+
- prior-art
24+
- retrieval-augmented-generation
25+
- llm-reranking
26+
- fail-open
27+
- graceful-degradation

COMMERCIAL-LICENSE.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Commercial License
2+
3+
This software is **dual-licensed**. Choose ONE:
4+
5+
## Option 1 — Open source (default): GNU AGPL-3.0-or-later
6+
Use, modify, and distribute under the GNU Affero General Public License, version 3
7+
or later (see [LICENSE](LICENSE)). Note the AGPL **network-use clause**: if you run a
8+
modified version to provide a service over a network, you must offer the complete
9+
corresponding source of your modified version to that service's users.
10+
11+
## Option 2 — Commercial license (alternative)
12+
If you do not wish to comply with the AGPL — e.g. to embed this software in a
13+
proprietary or closed-source product or hosted service without disclosing your
14+
source — obtain a separate commercial license from the copyright holder.
15+
16+
- **Licensor / copyright holder:** Gus IT LLC (Florida, USA)
17+
- **Contact:** gus@gusit.de
18+
19+
A commercial license provides the same software under negotiated terms that remove
20+
the AGPL source-disclosure obligations.
21+
22+
## Note on the technical disclosure
23+
The accompanying technical disclosure (`DEFENSIVE-PUBLICATION.md`) is published as
24+
public prior art; the **technique** is freely practiceable by anyone. This
25+
dual-license governs the use of **this source code and its derivatives**, not the
26+
underlying idea.
27+
28+
Copyright (c) 2026 Gus IT LLC. All rights reserved except as expressly granted above.

DEFENSIVE-PUBLICATION.md

Lines changed: 853 additions & 0 deletions
Large diffs are not rendered by default.

LICENSE

Lines changed: 661 additions & 0 deletions
Large diffs are not rendered by default.

NOTICE

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Hybrid RAG Ranking with Graceful LLM Fallback
2+
Copyright (c) 2026 Gus IT LLC (Florida, USA)
3+
4+
This software is dual-licensed under:
5+
(1) the GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later) — see LICENSE; or
6+
(2) a commercial license available from Gus IT LLC — see COMMERCIAL-LICENSE.md (contact gus@gusit.de).
7+
8+
This repository accompanies a defensive technical publication released to establish
9+
public prior art. The disclosed technique is freely practiceable; the licenses above
10+
govern this source code and its derivatives.

README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Hybrid RAG Ranking with Graceful LLM Fallback
2+
3+
> A two-stage retrieval ranker in which a deterministic, always-available lexical
4+
> stage owns the critical path and an optional language-model re-ranking stage —
5+
> bounded to a top-K subset and governed by a budget — runs off the critical path
6+
> and **fails open** to the deterministic result on any timeout, error, or budget
7+
> breach, without surfacing that failure to the caller.
8+
9+
---
10+
11+
**⚖️ DEFENSIVE PUBLICATION / PRIOR ART**
12+
13+
This repository is a **Technical Defensive Publication**. It is published to
14+
establish a dated, citable record of prior art so that the technique described
15+
herein remains free for anyone to practice and **cannot be patented by others**.
16+
17+
| Field | Value |
18+
|-------|-------|
19+
| Publisher / Copyright holder | **Gus IT LLC** (Florida, USA) |
20+
| Author | **Gustavo Assuncao, PhD** |
21+
| Publication date | **2026-06-25** |
22+
| Version | **1.0** |
23+
| Document type | Technical Defensive Publication (public prior art) |
24+
| Classification | Public |
25+
| License | AGPL-3.0-or-later (copyleft; commercial license available) |
26+
| Deposit channel | To be assigned (IP.com / Zenodo / arXiv) — establishes a public, dated, citable prior-art record |
27+
28+
![status](https://img.shields.io/badge/status-published-success)
29+
![type](https://img.shields.io/badge/type-defensive--publication-blue)
30+
![license](https://img.shields.io/badge/license-AGPL--3.0-green)
31+
![prior-art](https://img.shields.io/badge/prior--art-established_2026--06--25-informational)
32+
33+
---
34+
35+
## Abstract
36+
37+
Retrieval-augmented generation (RAG) pipelines increasingly insert a
38+
language-model (LLM) re-ranking stage between candidate retrieval and answer
39+
synthesis, because LLM re-rankers materially improve ordering quality. But LLM
40+
re-rankers are slow, expensive, rate-limited, and occasionally unavailable. The
41+
naive integration — call the retriever, then *await* the LLM re-ranker, then
42+
return — promotes the slow, failure-prone stage onto the **critical path**: the
43+
end-to-end latency, availability, and cost of retrieval all become hostage to the
44+
LLM provider. A single provider timeout or a tripped spend cap turns a sub-100 ms
45+
retrieval into a multi-second failure.
46+
47+
This publication describes a hybrid ranking architecture that inverts the
48+
dependency. A deterministic lexical stage (TF-IDF-style scoring with title and
49+
recency boosts) is the **critical path** and *always* returns a fully-ordered
50+
result within a tight latency budget. The LLM re-ranking stage is structurally a
51+
**non-critical-path enhancement**: it is invoked only on a bounded top-K subset of
52+
the already-ordered deterministic output, it is governed by a per-call budget and
53+
time bound, and — the central novelty — on **any** failure (bridge unavailability,
54+
timeout, malformed output, or budget breach) the system **fails open**, returning
55+
the deterministic ranking unchanged and *without surfacing the failure to the
56+
caller*. The contract guarantees a valid, ordered result on every call; the LLM
57+
can only ever *improve* the ordering, never degrade availability or latency.
58+
59+
The disclosure provides the architecture, the fail-open state machine, the
60+
top-K/budget cost-bounding mechanics, a data model, a clean-room reference
61+
implementation, a worked example, security and failure-mode analysis, framework
62+
mappings, an evaluation methodology, and an enumerated set of inventive claims
63+
(one independent plus fourteen dependent).
64+
65+
## Why this is published
66+
67+
We believe two-stage retrieval that *fails open from an LLM re-ranker to a
68+
deterministic ranker* is a robustness pattern that should remain **freely
69+
practiceable by everyone** — RAG infrastructure authors, search teams, and agent
70+
builders alike. Rather than seek a patent on the fail-open guarantee, Gus IT LLC
71+
publishes it defensively. By placing a complete, enabling, dated technical
72+
description in the public domain under AGPL-3.0-or-later, we create prior art that bars a
73+
later party from patenting the same technique and asserting it against
74+
practitioners. The reference implementation is original, clean-room, and
75+
dependency-light so that anyone can read it, run it, and adopt the pattern.
76+
77+
## Table of Contents
78+
79+
- **[DEFENSIVE-PUBLICATION.md](DEFENSIVE-PUBLICATION.md)** — the full technical
80+
whitepaper (architecture, mechanics, data model, claims, evaluation, appendices).
81+
- **[docs/PRIOR-ART.md](docs/PRIOR-ART.md)** — prior-art landscape and delta table.
82+
- **[docs/FIGURES.md](docs/FIGURES.md)** — all figures with captions.
83+
- **[docs/OPEN-SOURCE-APP.md](docs/OPEN-SOURCE-APP.md)** — planned open-source
84+
reference app and deployment sketch.
85+
- **[src/](src/)** — clean-room illustrative reference implementation
86+
([src/README.md](src/README.md)).
87+
- **[LICENSE](LICENSE)** — AGPL-3.0-or-later.
88+
- **[NOTICE](NOTICE)** — attribution and defensive-publication statement.
89+
- **[CITATION.cff](CITATION.cff)** — citation metadata.
90+
91+
## Planned open-source app
92+
93+
This repository is intended to seed a small open-source reference application: a
94+
self-contained hybrid RAG ranking service that demonstrates the fail-open pattern
95+
end-to-end, with a pluggable re-ranker adapter and a generic Kubernetes/AKS
96+
deployment sketch. See **[docs/OPEN-SOURCE-APP.md](docs/OPEN-SOURCE-APP.md)**.
97+
98+
## License & Citation
99+
100+
Licensed under the **GNU Affero General Public License v3.0** — see [LICENSE](LICENSE). The AGPL-3.0-or-later
101+
express patent grant is intentional for a prior-art release.
102+
103+
To cite this publication, see [CITATION.cff](CITATION.cff). Short form:
104+
105+
> Assuncao, Gustavo (2026). *Hybrid RAG Ranking with Graceful LLM Fallback.*
106+
> Technical Defensive Publication, v1.0, Gus IT LLC. Published 2026-06-25.

docs/FIGURES.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Figures
2+
3+
All figures from [`../DEFENSIVE-PUBLICATION.md`](../DEFENSIVE-PUBLICATION.md),
4+
collected with captions. They render natively on GitHub via Mermaid.
5+
6+
---
7+
8+
## Figure 1 — System architecture
9+
10+
The base ranker is the only path the caller strictly depends on; everything to the
11+
right of the gate is best-effort.
12+
13+
```mermaid
14+
graph TD
15+
Q[Query q + candidate set D] --> B[Deterministic Base Ranker<br/>TF-IDF + title/recency boosts]
16+
B --> OB[(Ordered base result O_B)]
17+
OB --> GATE{Overlay gate:<br/>enabled? &nbsp; budget OK? &nbsp; size > min?}
18+
GATE -- no --> RET[Return O_B]
19+
GATE -- yes --> TOPK[Select top-K subset D_K]
20+
TOPK --> M[LLM Re-ranker M<br/>listwise index ordering]
21+
M -- success + valid permutation --> MERGE[Merge: O_M over D_K,<br/>O_B tail preserved]
22+
M -- error / timeout / budget / malformed --> FALLBACK[Fail open]
23+
MERGE --> RET2[Return merged result]
24+
FALLBACK --> RET3[Return O_B silently]
25+
RET --> CALLER([Caller])
26+
RET2 --> CALLER
27+
RET3 --> CALLER
28+
M -. failure telemetry .-> METRICS[/Metrics: rerank_attempts,<br/>rerank_fallbacks, reasons/]
29+
```
30+
31+
---
32+
33+
## Figure 2 — Fail-open state machine
34+
35+
Every edge that is not a clean success funnels to `ReturnBase`, and `ReturnBase`
36+
never throws.
37+
38+
```mermaid
39+
stateDiagram-v2
40+
[*] --> Base
41+
Base --> Gate: O_B ready
42+
Gate --> ReturnBase: disabled / too few docs / over budget
43+
Gate --> AttemptRerank: enabled & within budget
44+
AttemptRerank --> Validate: adapter returned within deadline
45+
AttemptRerank --> FailOpen: error / timeout / 429 / empty
46+
Validate --> Merge: O_M is a valid permutation of D_K
47+
Validate --> FailOpen: malformed / not a permutation
48+
Merge --> ReturnMerged
49+
FailOpen --> ReturnBase: record reason, do NOT throw
50+
ReturnBase --> [*]
51+
ReturnMerged --> [*]
52+
```
53+
54+
---
55+
56+
## Figure 3 — Logical data model
57+
58+
`RERANK_EVENT` is telemetry-only; it never affects the returned `SCORED_DOC` list
59+
beyond setting `reranked` flags.
60+
61+
```mermaid
62+
erDiagram
63+
QUERY ||--o{ SCORED_DOC : ranks
64+
DOCUMENT ||--|| SCORED_DOC : becomes
65+
RANK_INVOCATION ||--o{ SCORED_DOC : produces
66+
RANK_INVOCATION ||--o| RERANK_EVENT : may_emit
67+
68+
DOCUMENT {
69+
string id
70+
string title
71+
string content
72+
timestamp updated_at
73+
}
74+
SCORED_DOC {
75+
int index "original position in D"
76+
float base_score "[0,1] from B"
77+
int final_rank "position in returned order"
78+
bool reranked "true if in top-K and merge applied"
79+
}
80+
RANK_INVOCATION {
81+
string query
82+
int candidate_count "|D|"
83+
int top_k "K used"
84+
string path "base | merged"
85+
int latency_ms
86+
}
87+
RERANK_EVENT {
88+
string outcome "success | fallback"
89+
string reason "timeout|error|429|budget|malformed|invalid_perm|empty"
90+
int tokens_estimated
91+
int deadline_ms
92+
}
93+
```
94+
95+
---
96+
97+
## Figure 4 — Worked-example sequence
98+
99+
Shows both the success merge and the fail-open branch returning `O_B` silently.
100+
101+
```mermaid
102+
sequenceDiagram
103+
participant C as Caller
104+
participant R as HybridRanker.rank
105+
participant B as BaseRanker
106+
participant G as OverlayGate
107+
participant M as LLM Adapter
108+
C->>R: rank(q, D, opts, adapter)
109+
R->>B: baseRank(q, D)
110+
B-->>R: O_B = [d3,d7,d1,d9,d5,...]
111+
R->>G: gate(enabled, |D|, budget)
112+
G-->>R: attempt (within budget)
113+
R->>M: rerank(q, topK=[d3,d7,d1,d9,d5], deadline=1500ms)
114+
alt success within deadline
115+
M-->>R: order [2,0,1,4,3]
116+
R->>R: validate permutation ✓
117+
R->>R: merge → [d1,d3,d7,d5,d9] ++ tail
118+
R-->>C: merged result (path=merged)
119+
else timeout / error / 429 / malformed
120+
M--xR: failure
121+
R->>R: record fallback reason
122+
R-->>C: O_B unchanged (path=base), no throw
123+
end
124+
```

0 commit comments

Comments
 (0)