DiscoveryVIP / AI EngineeringHelp Center

54. Retrieving relevant evidence

Module 11 · approximately 20 minutes

Open Interactive Lesson

Discover → Predict → Understand

How would you verify retrieving relevant evidence before allowing a real application to act?

Retrieval is a ranking operation over supplied documents, not a model memory test. This real local keyword method counts matched query terms and returns only matching passages. Inspect failures such as synonyms and outdated text rather than presenting a lexical score as semantic confidence. Relevance labels should be authored independently.

Apply this operation inside the context and knowledge systems stage of a complete application. Keep model proposals, deterministic checks and human authority separate.

Contract
The declared input, output and failure conditions an operation must satisfy.
Evidence
An actual source, executed result or independently authored expectation supporting a claim.

Working application operation

Run the normal case and connect each operation to the lesson concept.

// Fixture/local deterministic example. No model request is sent.
const E = require("./engine.js");
function feature(input) {
  return E.retrieve(input.query,input.documents,2).map(r=>({id:r.id,score:r.score}));
}
const input = {
  "query": "refund receipt",
  "documents": [
    {
      "id": "a",
      "text": "Refund requires receipt"
    },
    {
      "id": "b",
      "text": "Refund policy"
    }
  ]
};
Promise.resolve(feature(input)).then(value => {
  console.log(JSON.stringify(value));
}).catch(error => console.log("ERROR: " + error.message));

Exact independently authored expected result

[
  "[{\"id\":\"a\",\"score\":1},{\"id\":\"b\",\"score\":0.5}]"
]

Controlled alternative input

Predict how changing the input changes the actual result; compare against an independent expected case.

// Fixture/local deterministic example. No model request is sent.
const E = require("./engine.js");
function feature(input) {
  return E.retrieve(input.query,input.documents,2).map(r=>({id:r.id,score:r.score}));
}
const input = {
  "query": "hours",
  "documents": [
    {
      "id": "a",
      "text": "Refund only"
    }
  ]
};
Promise.resolve(feature(input)).then(value => {
  console.log(JSON.stringify(value));
}).catch(error => console.log("ERROR: " + error.message));

Exact independently authored expected result

[
  "[]"
]

Boundary or independent transfer

Investigate the exact boundary or second application context. Explain what the test does not establish.

// Fixture/local deterministic example. No model request is sent.
const E = require("./engine.js");
function feature(input) {
  return E.retrieve(input.query,input.documents,2).map(r=>({id:r.id,score:r.score}));
}
const input = {
  "query": "open",
  "documents": [
    {
      "id": "b",
      "text": "Open at 9"
    }
  ]
};
Promise.resolve(feature(input)).then(value => {
  console.log(JSON.stringify(value));
}).catch(error => console.log("ERROR: " + error.message));

Exact independently authored expected result

[
  "[{\"id\":\"b\",\"score\":1}]"
]

Executable independent behavior contract

An explicit assertion compares the operation with its independently authored expected result.

// Fixture/local deterministic example. No model request is sent.
const E = require("./engine.js");
function feature(input) {
  return E.retrieve(input.query,input.documents,2).map(r=>({id:r.id,score:r.score}));
}
const input = {
  "query": "refund receipt",
  "documents": [
    {
      "id": "a",
      "text": "Refund requires receipt"
    },
    {
      "id": "b",
      "text": "Refund policy"
    }
  ]
};
Promise.resolve(feature(input)).then(value => {
  const expected = [{"id":"a","score":1},{"id":"b","score":0.5}];
  if (JSON.stringify(value) !== JSON.stringify(expected)) throw Error("Behavior contract failed");
  console.log("Contract verified");
}).catch(error => console.log("ERROR: " + error.message));

Exact independently authored expected result

[
  "Contract verified"
]

Investigate an unsafe application integration

This intentional integration defect wraps a valid result in an unverified record and marks it stored without review. Repair the boundary; a successful calculation does not authorize storage.

// Fixture/local deterministic example. No model request is sent.
const E = require("./engine.js");
function feature(input) {
  const observed = (() => { return E.retrieve(input.query,input.documents,2).map(r=>({id:r.id,score:r.score})); })();
return Promise.resolve(observed).then(value => ({unverifiedResult:value, storedWithoutReview:true}));
}
const input = {
  "query": "refund receipt",
  "documents": [
    {
      "id": "a",
      "text": "Refund requires receipt"
    },
    {
      "id": "b",
      "text": "Refund policy"
    }
  ]
};
Promise.resolve(feature(input)).then(value => {
  console.log(JSON.stringify(value));
}).catch(error => console.log("ERROR: " + error.message));

Exact independently authored expected result

[
  "{\"unverifiedResult\":[{\"id\":\"a\",\"score\":1},{\"id\":\"b\",\"score\":0.5}],\"storedWithoutReview\":true}"
]

Important source operations

Line 1: // Fixture/local deterministic example. No model request is sent.
Retrieval is a ranking operation over supplied documents, not a model memory test. Inspect this operation and its inputs.
Line 2: const E = require("./engine.js");
Load the actual deterministic engine implementation; select engine.js in project exports to inspect it.
Line 3: function feature(input) {
This function implements the specific lesson operation and can be tested independently of a UI.
Line 4: return E.retrieve(input.query,input.documents,2).map(r=>({id:r.id,score:r.score}));
Retrieval is a ranking operation over supplied documents, not a model memory test. Inspect this operation and its inputs.
Line 5: }
Retrieval is a ranking operation over supplied documents, not a model memory test. Inspect this operation and its inputs.
Line 6: const input = {
Use explicit fictional input so another learner can reproduce the case.
Line 7: "query": "refund receipt",
Retrieval is a ranking operation over supplied documents, not a model memory test. Inspect this operation and its inputs.
Line 8: "documents": [
Retrieval is a ranking operation over supplied documents, not a model memory test. Inspect this operation and its inputs.
Line 9: {
Retrieval is a ranking operation over supplied documents, not a model memory test. Inspect this operation and its inputs.
Line 10: "id": "a",
Retrieval is a ranking operation over supplied documents, not a model memory test. Inspect this operation and its inputs.
Line 11: "text": "Refund requires receipt"
Retrieval is a ranking operation over supplied documents, not a model memory test. Inspect this operation and its inputs.
Line 12: },
Retrieval is a ranking operation over supplied documents, not a model memory test. Inspect this operation and its inputs.
Line 13: {
Retrieval is a ranking operation over supplied documents, not a model memory test. Inspect this operation and its inputs.
Line 14: "id": "b",
Retrieval is a ranking operation over supplied documents, not a model memory test. Inspect this operation and its inputs.
Line 15: "text": "Refund policy"
Retrieval is a ranking operation over supplied documents, not a model memory test. Inspect this operation and its inputs.
Line 16: }
Retrieval is a ranking operation over supplied documents, not a model memory test. Inspect this operation and its inputs.
Line 17: ]
Retrieval is a ranking operation over supplied documents, not a model memory test. Inspect this operation and its inputs.
Line 18: };
Retrieval is a ranking operation over supplied documents, not a model memory test. Inspect this operation and its inputs.
Line 19: Promise.resolve(feature(input)).then(value => {
Handle both synchronous and asynchronous operations, then inspect actual completion.
Line 20: console.log(JSON.stringify(value));
Observe real execution output; compare it with the independently authored case.
Line 21: }).catch(error => console.log("ERROR: " + error.message));
Observe real execution output; compare it with the independently authored case.

Build → Test

Repair the integration so the exact output is [{"id":"a","score":1},{"id":"b","score":0.5}]. Remove the unverified storage claim and return the actual operation result. Add a test that rejects storage without approval.

Hint 1

Read the original operation and compare actual output with the independent expected case.

Hint 2

The integration wraps the legitimate result and adds storedWithoutReview:true without a real validation/approval boundary.

Hint 3

Return the operation result directly, as the finished reference does. For actual storage use validate, business rules and an explicit approval gate.

Common failures and security

Treating a well-formed or successful result as permission to store, send or trust it. Inspect the exact contract and the execution trace.

Use fictional or consented data. Keep secrets server-side. Source data and model output are untrusted; deterministic checks do not prove factual correctness.

Explain → Reflect → Extend

Which observation came from code execution? Which expectation was authored independently? What must a human review before using this operation in a real workflow?

Change one domain requirement, write the expected behavior first and add a normal, boundary and failure test. Explain whether the task needs a model at all.

Three optional AI learning prompts

Explain This Application Concept
Explain This Application Concept
Objective: Retrieving relevant evidence
Source:
// Fixture/local deterministic example. No model request is sent.
const E = require("./engine.js");
function feature(input) {
  return E.retrieve(input.query,input.documents,2).map(r=>({id:r.id,score:r.score}));
}
const input = {
  "query": "refund receipt",
  "documents": [
    {
      "id": "a",
      "text": "Refund requires receipt"
    },
    {
      "id": "b",
      "text": "Refund policy"
    }
  ]
};
Promise.resolve(feature(input)).then(value => {
  console.log(JSON.stringify(value));
}).catch(error => console.log("ERROR: " + error.message));

Expected: [{"id":"a","score":1},{"id":"b","score":0.5}]
Known failure: Treating a well-formed or successful result as permission to store, send or trust it. Inspect the exact contract and the execution trace.
Explain source operations and security boundaries. Propose tests. Do not claim execution or request secrets; I will verify using actual runtime and independent evidence.
Help Me Implement the Next Feature
Help Me Implement the Next Feature
Objective: Retrieving relevant evidence
Source:
// Fixture/local deterministic example. No model request is sent.
const E = require("./engine.js");
function feature(input) {
  return E.retrieve(input.query,input.documents,2).map(r=>({id:r.id,score:r.score}));
}
const input = {
  "query": "refund receipt",
  "documents": [
    {
      "id": "a",
      "text": "Refund requires receipt"
    },
    {
      "id": "b",
      "text": "Refund policy"
    }
  ]
};
Promise.resolve(feature(input)).then(value => {
  console.log(JSON.stringify(value));
}).catch(error => console.log("ERROR: " + error.message));

Expected: [{"id":"a","score":1},{"id":"b","score":0.5}]
Known failure: Treating a well-formed or successful result as permission to store, send or trust it. Inspect the exact contract and the execution trace.
Explain source operations and security boundaries. Propose tests. Do not claim execution or request secrets; I will verify using actual runtime and independent evidence.
Review and Debug My Code
Review and Debug My Code
Objective: Retrieving relevant evidence
Source:
// Fixture/local deterministic example. No model request is sent.
const E = require("./engine.js");
function feature(input) {
  return E.retrieve(input.query,input.documents,2).map(r=>({id:r.id,score:r.score}));
}
const input = {
  "query": "refund receipt",
  "documents": [
    {
      "id": "a",
      "text": "Refund requires receipt"
    },
    {
      "id": "b",
      "text": "Refund policy"
    }
  ]
};
Promise.resolve(feature(input)).then(value => {
  console.log(JSON.stringify(value));
}).catch(error => console.log("ERROR: " + error.message));

Expected: [{"id":"a","score":1},{"id":"b","score":0.5}]
Known failure: Treating a well-formed or successful result as permission to store, send or trust it. Inspect the exact contract and the execution trace.
Explain source operations and security boundaries. Propose tests. Do not claim execution or request secrets; I will verify using actual runtime and independent evidence.
Next full lesson