{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/tale-dev/json-schema/tale-dev-knowledge-search-result-schema.json",
  "title": "KnowledgeSearchResult",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/tale-dev-knowledge-api-openapi.yml#/components/schemas/KnowledgeSearchResult",
  "type": "object",
  "required": [
    "hits",
    "diagnostics"
  ],
  "properties": {
    "hits": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/KnowledgeHit"
      },
      "description": "In fused order (`fusedScore` descending), one passage per repeated text; at equal `fusedScore` a passage the keyword leg ranked precedes one only the vector leg found (an exact term is stronger evidence than a nearest neighbour), then the lower row identity. Every candidate is checked against its live document BEFORE fusion, so a refused one never holds a rank, and the page is cut last — `limit` never costs a readable hit"
    },
    "diagnostics": {
      "type": "object",
      "required": [
        "bm25",
        "dense",
        "reranked",
        "cached",
        "admitted",
        "legs"
      ],
      "properties": {
        "bm25": {
          "type": "boolean",
          "description": "False when the keyword index was unavailable and only the vector leg ran"
        },
        "dense": {
          "type": "boolean",
          "description": "False when the corpus could not serve the vector leg (its table, or a column this release selects, is missing) and only the keyword leg ran — the twin of `bm25`, so a dead leg is never silent"
        },
        "reranked": {
          "type": "boolean",
          "description": "Always false: Tale ships no reranker. The flag stays in the response for compatibility"
        },
        "cached": {
          "type": "boolean",
          "description": "Always false: Tale ships no semantic cache. The flag stays in the response for compatibility"
        },
        "admitted": {
          "type": "integer",
          "minimum": 0,
          "description": "Candidates that passed the live-document check and were fused, before repeated passages were dropped and the page was cut"
        },
        "legs": {
          "type": "object",
          "additionalProperties": true,
          "description": "Every leg that RAN, keyed by leg (`documents:keyword`, `documents:dense`, `web:keyword`, `web:dense`), with how many admitted candidates it contributed to fusion — counts after the live-document check, `0` when it ran and nothing survived that check or the `minSimilarity` floor. A leg that could not run is absent and named by `bm25` / `dense`"
        }
      }
    }
  },
  "$defs": {
    "KnowledgeHit": {
      "type": "object",
      "required": [
        "id",
        "corpus",
        "text",
        "source",
        "chunkIndex",
        "score",
        "fusedScore",
        "matchedLegs",
        "similarity",
        "keywordScore"
      ],
      "properties": {
        "id": {
          "type": "string",
          "description": "Stable row identity within its corpus"
        },
        "corpus": {
          "type": "string",
          "enum": [
            "documents",
            "web"
          ]
        },
        "text": {
          "type": "string",
          "description": "The passage, contextual header included"
        },
        "source": {
          "type": "object",
          "required": [
            "ref",
            "title"
          ],
          "properties": {
            "ref": {
              "type": "string",
              "description": "The blob reference the corpus keys a document by, or the page URL for a web hit — cite `documentId` to open a document"
            },
            "title": {
              "type": [
                "string",
                "null"
              ]
            },
            "url": {
              "type": [
                "string",
                "null"
              ],
              "description": "Present for web pages"
            },
            "modifiedAt": {
              "type": [
                "integer",
                "null"
              ],
              "minimum": 0,
              "description": "Epoch milliseconds"
            },
            "projectId": {
              "type": [
                "string",
                "null"
              ],
              "description": "The project the document is filed under; null for a Hub document and for a web page"
            },
            "conversationId": {
              "type": [
                "string",
                "null"
              ],
              "description": "The conversation an emailed attachment arrived on; present only for those"
            },
            "documentId": {
              "type": "string",
              "description": "The active document that exposes `ref` in the hit’s own scope. For a Hub hit (`projectId` null) it is the id `GET /api/v1/documents/{id}` takes; for a project hit it is the file id the project routes take (`GET /api/v1/projects/{projectId}/files/{documentId}/content`, `DELETE …/files/{documentId}`) — `/api/v1/documents/{id}` answers 404 for a project file. Absent for web pages, thread uploads and emailed attachments"
            }
          }
        },
        "chunkIndex": {
          "type": "integer",
          "description": "Position of the passage inside its document"
        },
        "offset": {
          "type": "integer",
          "description": "Character position of the passage within the document’s full text; absent when it cannot be established"
        },
        "score": {
          "type": "number",
          "description": "The surviving leg copy’s own relevance score — BM25 when the keyword leg found the passage, else its cosine; scales differ per leg, so read `keywordScore` and `similarity`, which name theirs"
        },
        "fusedScore": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "The rank-fusion order key the hits are sorted by: Σ 1/(60+rank) over the legs that ranked the passage, divided by the best score possible given the legs that contributed candidates to THIS response (`diagnostics.legs`) — so the same passage reads 1.0 when both document legs ranked it first in a two-leg search and 0.667 when a third leg (a web neighbour) contributed too. A RANK — comparable only within one response, never a confidence, and not stable across searches. Threshold on `similarity` instead"
        },
        "legs": {
          "type": "integer",
          "minimum": 1,
          "maximum": 2,
          "description": "How many retrieval legs of the corpus found the passage: 2 when the keyword and the vector leg agreed, 1 when only one did"
        },
        "matchedLegs": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "documents:keyword",
              "documents:dense",
              "web:keyword",
              "web:dense"
            ]
          },
          "description": "Which legs ranked the passage — the leg that produced `score` is the first one"
        },
        "similarity": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "maximum": 1,
          "description": "The dense (vector) leg’s cosine similarity when it ranked the passage, on the embedding model’s own 0..1 scale — the number to threshold the vector leg on, and what `minSimilarity` floors; null when only the keyword leg found it — keep such a hit, its `keywordScore` is the evidence"
        },
        "keywordScore": {
          "type": [
            "number",
            "null"
          ],
          "description": "The keyword leg’s BM25 weight when it ranked the passage (unbounded, relative to the corpus); null when only the vector leg found it"
        },
        "rerankScore": {
          "type": "number",
          "description": "Never present: Tale ships no reranker. The property stays in the schema for compatibility"
        }
      }
    }
  }
}