THE LINUX FOUNDATION PROJECTS
Tl;DR: Agentic AI treats retrieval rank as ground truth, so Top-K search can make an agent act confidently on an irrelevant result. Better retrieval (hybrid search, RRF, reranking) improves ranking but gives no “I don’t know” signal. This post adds a confidence layer that sits between retrieval and action: quantify a composite confidence score (score magnitude, gap, coherence, freshness, authority), threshold it by query type and action intent, then abstain on a graduated ladder (act, caveat, clarify, escalate, hard abstain). It builds on OpenSearch primitives: normalization processors, min_score, script_score, and reranking via ML Commons.

Agentic AI has moved retrieval from a supporting role to a foundation. When an autonomous agent plans, reasons, and iteratively calls tools to answer a question, it depends on retrieval to supply relevant, timely, and complete context at every step. OpenSearch has invested heavily in making that retrieval better and more accessible to agents: hybrid search, native agentic search (a conversational agent that plans tool use and generates query DSL from natural language, generally available since OpenSearch 3.2), the agentic chat, investigation agent, and agentic memory capabilities built into OpenSearch Dashboards, and rigorous relevance evaluation.

But there is a dimension that better retrieval and even native agentic orchestration does not address: knowing when not to act. Agentic search can plan tool calls and generate an optimized query; the investigation agent can autonomously plan, execute, and reflect through a multi-step root-cause analysis. Neither ships a built-in signal for “none of what I retrieved is good enough to act on.” A retrieval system that always returns its best guess can mislead an agent into acting confidently on a result that is, in fact, irrelevant.

This post introduces a practical confidence layer: a step that gives agents the ability to say “I’m not confident enough to act on this.” It shows how to implement it with OpenSearch primitives, as a complement to (not a replacement for) OpenSearch’s native agentic tooling.

This is a conceptual deep dive with illustrative code. The snippets map to real OpenSearch features (normalization processors, min_score, script_score, and reranking via ML Commons); the composite-confidence and abstention logic lives in your agent orchestration layer.

The problem: when agents trust blindly

Consider a realistic failure. An internal knowledge agent receives the query “how to rotate API keys in production.” It retrieves a top-ranked document, treats rank #1 as ground truth, and follows a deprecated 2022 runbook. The result is a production incident that could have been avoided if the agent had recognized that no sufficiently relevant document existed.

The underlying issue is that agents tend to treat retrieval rank as ground truth. Top-K retrieval returns K results by construction even when nothing relevant exists in the index. There is no built-in signal that says “none of these are good enough.”

In a single-shot search interface, a human reviews the results and applies judgment. In an agentic workflow, the agent acts on the results directly, and one weak retrieval can compound: the agent builds subsequent reasoning and tool calls on wrong context, producing a cascading chain of errors.

Why Top-K falls short in agentic workflows

Several characteristics of raw retrieval scores make them unreliable as a trust signal for autonomous action:

  • Scores are not normalized across methods. BM25 scores are theoretically unbounded and in practice commonly fall in the 0 to 15 range, while L2 distance for vector search sits between 0 and 1. Comparing or combining them directly is comparing different scales.
  • Scores are not comparable across queries. A BM25 score of 8.5 on one query does not represent the same relevance as 8.5 on another, because scores depend on term frequencies and corpus statistics specific to each query.
  • There is no “I don’t know” signal. For vector (k-NN) queries, Top-K returns K results by construction; for BM25, an irrelevant query returns either no hits or hits with very low scores. In neither case does the agent get an explicit signal that nothing is good enough, and a low-but-nonzero score is easy to mistake for a usable answer.

Setting up the base: common approaches and their gaps

Before adding a confidence layer, it is worth getting the retrieval foundation right. OpenSearch supports three widely used techniques that meaningfully improve retrieval quality.

1. Hybrid retrieval with score normalization

Combining BM25 with vector (k-NN) search captures both keyword precision and semantic recall. OpenSearch implements this with a hybrid query plus a normalization processor search pipeline (introduced in OpenSearch 2.10) that normalizes and combines sub-query scores. Normalization rescales BM25 and vector scores onto a common range so they can be combined; self-managed OpenSearch supports min-max, L2, and z-score techniques. Managed offerings such as Amazon OpenSearch Serverless currently support min-max and L2 normalization with arithmetic-mean, geometric-mean, and harmonic-mean combination. Please check your OpenSearch version and deployment mode before assuming z-score is available.

PUT /_search/pipeline/nlp-search-pipeline
{
  "phase_results_processors": [
    {
      "normalization-processor": {
        "normalization": { "technique": "min_max" },
        "combination": {
          "technique": "arithmetic_mean",
          "parameters": { "weights": [0.3, 0.7] }
        }
      }
    }
  ]
}

2. Reciprocal Rank Fusion (RRF)

RRF merges ranked lists using rank position rather than raw scores, which sidesteps the score-calibration problem:

RRF_score(d) = Σ 1 / (k + rank_i(d))     # k = 60 is a common smoothing constant

3. Reranking with a cross-encoder

A cross-encoder rescores the top candidates using full query-document attention, producing more precise ordering as a second pass. OpenSearch supports this through the rerank processor via ML Commons:

"response_processors": [
  {
    "rerank": {
      "ml_opensearch": { "model_id": "<cross_encoder_model_id>" },
      "context": { "document_fields": ["content"] }
    }
  }
]

4. Native agentic search

OpenSearch also lets an agent generate the query itself. Agentic search registers a conversational agent backed by an LLM and a QueryPlanningTool: you send a natural-language question, and the agent plans tool use, produces the query DSL, executes it, and returns a natural-language summary of what it did. Amazon OpenSearch Service supports this starting with OpenSearch version 3.3.

Separately, OpenSearch Dashboards ships:

  1. Agentic chat (natural-language-to-PPL for log exploration),
  2. An investigation agent (a goal-driven agent that autonomously plans, executes, and reflects for root-cause analysis), and
  3. Agentic memory (session continuity across both).

These are agent-facing conveniences for querying where they still hand back a ranked or generated result for the calling agent or user to act on.

Why these are not sufficient on their own

Each technique improves ranking or query generation, but none provides a trustworthy trust signal. Consider the query “how to rotate API keys in production,” where the correct document ranks modestly on keywords but strongly on semantics, and a deprecated runbook ranks #1 on keyword overlap:

  • Hybrid search with min-max normalization rescales scores against the candidate set that was returned, so a high top score reports that a document is the best of that set, not that it’s relevant. (With min-max, a document that matches every subquery clause maps to 1.0; one that matches only some clauses lands lower, for example around 0.5 for one of two clauses.) The deprecated runbook still scores highly when it’s the strongest match in a set that contains no good answer, and the agent trusts it.
  • RRF discards score information entirely. It can surface the “best of irrelevant results” with no way to threshold on confidence, because rank fusion has no notion of absolute relevance.
  • Reranking orders all candidates, including a set that may be uniformly irrelevant. A cross-encoder logit is designed for ordering, not calibrated confidence, and the processor still returns a ranked list.
  • Agentic search plans and executes a query competently, but the QueryPlanningTool still returns whatever the generated query matches. It does not evaluate whether the match is good enough to act on.

None of these lets the agent conclude: “I’m not confident enough to act.” That is the gap the confidence layer fills, as a layer that sits downstream of any of these retrieval paths including agentic search itself.

The confidence layer: quantify, threshold, abstain

The confidence layer sits between retrieval and action. It takes the (normalized) retrieval results and decides whether the agent should act, act with a caveat, seek clarification, escalate, or decline. It rests on three pillars.

Pillar 1: Quantify – multi-signal confidence scoring

A single score can be misleading, so the confidence layer combines several signals into a composite confidence value:

  1. Score magnitude: How high is the top normalized score? Interpret this relative to the retrieval technique, because the top score is often technique-dependent. With min-max normalization and a single hybrid clause, for example, the top hit is always 1.0, so magnitude alone carries little signal; treat it as meaningful only alongside the other signals below.
  2. Score gap: The difference between the #1 and #2 results. A large gap suggests a clear winner; a small gap suggests ambiguity. This signal is also technique-dependent: with min-max normalization, the gap shifts with how many hits are returned (two hits might produce scores of [1.0, 0.001] with a gap of 0.999, while three hits produce [1.0, 0.5, 0.001] with a gap of 0.5), so compare gaps within a technique rather than across them.
  3. Result coherence: Do the top results point to the same answer, or do they disagree? Compute this in the agent layer from the retrieved document contents, for example by measuring embedding agreement among the top hits.
  4. Freshness: How recently were the top documents updated? (Relevant to the deprecated-runbook case.) This comes from a document field such as a last_updated timestamp indexed alongside the content.
  5. Source authority: Official documentation versus a forum post versus deprecated content. This relies on a document field (such as a source_type or authority score) that you populate at index time, or on a reranking model that factors in such metadata.

Signals 3-5 are not intrinsic to the retrieval scores; they draw on document metadata you index (freshness, authority) and on post-retrieval analysis in the agent layer (coherence), optionally reinforced by reranking through ML Commons. For hybrid queries, the normalization processor unifies raw scores; the agent layer then computes composite confidence from the signals above:

def compute_confidence(results):
    hits = results["hits"]["hits"]
    scores = [hit["_score"] for hit in hits]

    score_magnitude = scores[0]
    score_gap = scores[0] - scores[1] if len(scores) > 1 else 0
    coherence = compute_coherence(hits)      # agreement among top results
    freshness = avg_freshness(hits)          # recency of top documents
    authority = avg_authority(hits)          # source authority signal

    confidence = (
        0.35 * score_magnitude +
        0.25 * score_gap +
        0.20 * coherence +
        0.10 * freshness +
        0.10 * authority
    )
    return confidence

The weights above are a starting point; tune them against a judged query set for your corpus, as described in Optimizing hybrid search in OpenSearch.

Some of these signals can also be pushed into OpenSearch at query time. For example, script_score can factor authority and freshness directly into ranking for non-hybrid queries:

POST /index/_search
{
  "query": {
    "script_score": {
      "query": { "match": { "content": "rotate API keys" } },
      "script": {
        "source": "_score * (1 + doc['authority'].value * 0.3 + doc['freshness'].value * 0.2)"
      }
    }
  }
}

Pillar 2: Threshold – adaptive decision boundaries

A single static cutoff does not work across different kinds of requests. A confidence of 0.6 might be acceptable for an exploratory read but clearly insufficient for an irreversible bulk action. Thresholds should adapt to two factors:

  • Query type: a factual lookup demands higher confidence than an exploratory query.
  • Action intent: a read-only operation is lower-stakes than one that executes an action.
Query type Intent Threshold
Factual lookup read_only 0.75
Factual lookup execute_action 0.90
Exploratory read_only 0.50
Exploratory execute_action 0.70
Troubleshooting execute_action 0.85

Treat these values as a starting point, not fixed constants. Derive them empirically: assemble a judged set of queries for your corpus, sweep candidate thresholds, and pick the value per (query type, intent) cell that best separates queries that should act from those that should abstain (for example, by maximizing F1 or by holding false-acts under a target rate). Because a static cutoff rarely generalizes across query classes, revisit the table as your corpus and traffic mix shift, and consider deriving the boundary dynamically from the score distribution of each result set (such as a percentile of the returned scores, or the mean plus a multiple of the standard deviation) rather than hardcoding a single number. The evaluation methodology in Evaluating agentic search in OpenSearch is a good basis for this tuning.

In recent OpenSearch versions, min_score applies to hybrid queries after normalization, so you can enforce a floor at query time (verify the minimum version against the hybrid query release notes for your cluster, since this behavior was added after the initial hybrid query release):

POST /index/_search?search_pipeline=nlp-search-pipeline
{
  "min_score": 0.75,
  "query": {
    "hybrid": {
      "queries": [
        { "match": { "content": "rotate API keys" } },
        { "neural": { "embedding": { "query_text": "rotate API keys", "model_id": "<model_id>" } } }
      ]
    }
  }
}

One limitation to keep in mind: min_score is not always available on hybrid queries. If you add a sort clause to the hybrid query, for example to factor freshness or authority into ordering, sorting takes over from score-based ranking and min_score no longer applies. In that case, and on clusters where min_score is not yet applied to normalized hybrid scores, enforce the threshold in the agent orchestration layer instead:

def get_threshold(query_type, intent):
    thresholds = {
        ("factual", "read_only"): 0.75,
        ("factual", "execute_action"): 0.90,
        ("exploratory", "read_only"): 0.50,
        ("exploratory", "execute_action"): 0.70,
        ("troubleshooting", "execute_action"): 0.85,
    }
    return thresholds.get((query_type, intent), 0.75)

Pillar 3: Abstain – the graduated guardrail

Abstention is the actual guardrail: the point at which the agent declines to act. Rather than a binary act/refuse switch, a graduated response degrades gracefully based on how far confidence sits from the threshold:

def decide_action(confidence, threshold, results):
    margin = confidence - threshold

    if margin >= 0:
        return act(results)                        # ACT - respond normally
    elif margin > -0.05:
        return respond_with_caveat(results)        # CAVEAT - answer, flag uncertainty
    elif margin > -0.15:
        return clarify()                           # CLARIFY - ask a narrowing question
    elif margin > -0.25:
        return escalate()                          # ESCALATE - route to a human
    else:
        return hard_abstain()                      # HARD ABSTAIN - decline to act

This ladder-act, caveat, clarify, escalate, hard abstain-prevents cascading hallucinations at the source, because the agent stops before building further reasoning on a weak retrieval.

Putting it together: the complete pipeline

The end-to-end flow becomes:

  1. Retrieve using hybrid search, with a normalization processor unifying BM25 and vector scores (optionally followed by reranking via ML Commons).
  2. Quantify a composite confidence score from score magnitude, score gap, coherence, freshness, and authority.
  3. Threshold using an adaptive boundary derived from query type and action intent.
  4. Decide via the graduated abstention ladder.

The confidence layer scales the agent response to the confidence it can measure: it acts when the margin is positive, discloses the uncertainty when the margin is small, and declines when the margin is large and negative.

A concrete example: real estate property management

To make this tangible, consider a property-management assistant backed by four OpenSearch indexes:

Index Domain Key fields
re_leases_v2 Lease agreements tenant, property, lease_type
re_work_orders_v2 Maintenance priority, status, category
re_properties_v2 Properties type, occupancy_rate
re_tenants_v2 Tenants company, industry

We compare two configurations across five queries: a basic setup (hybrid search, no guardrails) and one with the confidence layer enabled. The confidence and margin values below are illustrative, computed from mocked retrieval scores using the weights and thresholds shown earlier.

Query Scenario Basic (no guardrail) With guardrail
“Show me the early termination clause for TechNova’s lease” Safe factual read Returns the answer Act – answers (confidence 0.85, margin +0.10)
“Suspend all tenants who defaulted on rent in the last 3 months” Dangerous bulk action Suspends tenants including some with strong payment histories Escalate – routes to a leasing manager for verification
“Auto-close all resolved HVAC tickets from last quarter” Bulk system action Closes all 12 tickets, including 4 with pending follow-ups Caveat – answers but flags the 4 tickets with pending follow-ups
“Send a lease renewal offer to all tenants in buildings with good occupancy near downtown” Vague bulk outreach Sends legally binding offers based on undefined thresholds Clarify – asks which occupancy percentage, which area, and whether to review the list first
“What is the best restaurant near Times Square?” Off-domain Fabricates a recommendation from property amenities Hard abstain – declines as out of domain

The pattern is consistent: without a confidence layer, the agent acts on every query, including the dangerous and the irrelevant. With one, its response degrades in proportion to how far confidence falls below threshold-caveat, clarify, escalate, or hard abstain, instead of a wrong answer delivered with full confidence.

Key takeaways

  • Top-K retrieval is not sufficient for agentic AI, because it always returns results even when nothing relevant exists.
  • Better retrieval (hybrid search, RRF, reranking) improves ranking but does not provide an “I don’t know” signal.
  • The confidence layer of quantify, threshold, and abstain fills the gap between retrieval and action.
  • Thresholds should be query-type and intent-aware; a single static cutoff does not hold across query classes.
  • Graduated abstention (act, caveat, clarify, escalate, hard abstain) helps prevent cascading errors at the source.
  • OpenSearch supports the building blocks natively: normalization processors, min_score for hybrid queries, script_score/function_score, agentic search, and reranking via ML Commons.

Next steps

Then, prototype a confidence layer in your agent orchestration: start with the composite-confidence function, add an adaptive threshold table for your query and action types, and wire in the graduated abstention ladder. Measure the effect against your own judged queries, and share what you learn with the community.

Authors

  • Chanpreet Singh

    Chanpreet Singh is a Senior Consultant at AWS with 19 years of industry experience, specializing in Data Analytics and AI/ML solutions. He partners with enterprise customers to architect and implement cutting-edge solutions in Big Data, Machine Learning, and Generative AI using AWS native services, partner solutions and open-source technologies. A passionate technologist and problem solver, he balances his professional life with nature exploration, reading, and quality family time.

    View all posts
  • Shatakshi Pandey

    Shatakshi Pandey is a Lead Delivery Consultant at AWS Professional Services with over 6 years of experience in Data Analytics and AI/ML. She partners with global enterprise customers to navigate the complexities of cloud migration and architectural re-engineering, transforming legacy workloads into scalable, cloud-native solutions powered by AWS Glue, Amazon Redshift, and OpenSearch. Her expertise spans high-performance Data Lakes and Warehousing architectures that help organizations unlock the full potential of their data at scale. Outside of work, she is a movie enthusiast and a bibliophile with a deep appreciation for art and literature.

    View all posts