# Search and ranking

Reliora Stage 2 uses deterministic lexical retrieval. It does not use embeddings, an LLM, network services, or hidden popularity metrics.

## Candidate selection

The query is normalized into unique lowercase tokens. Common stop words are removed. Exact token matches are accepted; conservative prefix matching is used only when one side has at least five characters. When `--project-context` is supplied, candidates must match at least one context token before scoring.

## Actual scoring components

Query-token matches are weighted by the field in which they occur:

| Field | Weight per matching query token |
| --- | ---: |
| tags | 9 |
| title | 8 |
| problems | 7 |
| task | 5 |
| solution and why-it-worked | 4 |
| project context | 4 |
| applicability | 4 |
| failed attempts | 3 |
| warnings | 2 |

An exact phrase found in any searchable field adds 12 before coverage scaling. The relevance subtotal is multiplied by `0.6 + 0.4 × query coverage`, so a one-word overlap cannot masquerade as complete coverage.

Feedback provides only a bounded tie-scale adjustment from -1.5 to +2.5. Success helps, partial use helps less, failure reduces, and not-applicable/outdated outcomes reduce conservatively. Generic popularity cannot overwhelm a clearly more relevant project-specific record.

`scoreBreakdown` exposes every scaled field component, `exactPhrase`, the coverage multiplier used, and the final feedback adjustment. Adding all fields plus exact phrase and feedback reconstructs the raw `score` within rounding. `coverageMultiplier` is reported as an explanatory multiplier and is not added again.

## Match levels

Levels are derived from measured coverage and pre-feedback relevance:

- `strong`: at least 75% query-token coverage and relevance of at least 18;
- `moderate`: at least 40% coverage and relevance of at least 8;
- `weak`: every other positive result.

These labels communicate retrieval evidence, not correctness. An agent must still inspect project context, applicability, warnings, verification, confidence, feedback, and current code.

## Duplicate warnings

Before recording, Reliora searches a query built from the candidate title, tags, and first problems. Strong or moderate similarities return up to three `SIMILAR_EXPERIENCE_FOUND` warnings with IDs, locators, and match levels. Exact title/solution/applicability equality is strong; a nominally strong lexical result without context or applicability overlap is reduced to moderate.

Warnings are deliberately soft. They encourage feedback or refinement but never prevent a distinct, justified save.

## Known limitations

Lexical search can miss synonyms, paraphrases, and misspellings. Match levels are not calibrated probabilities. The fixed weights and thresholds are inspectable MVP behavior; semantic retrieval is deferred rather than simulated.
