diff --git a/.changeset/38692-search-knowledge-score-text.md b/.changeset/38692-search-knowledge-score-text.md new file mode 100644 index 00000000000..f0f615845aa --- /dev/null +++ b/.changeset/38692-search-knowledge-score-text.md @@ -0,0 +1,11 @@ +--- +'@objectstack/service-knowledge': patch +'@objectstack/skills': patch +--- + +docs(knowledge): `search_knowledge` says what a hit's score means, and the AI skill documents `source.retrieval.mode` + +Clause-②: no +Metadata-protocol: none + +The `search_knowledge` description now says that a hit's `score` gives only its order among the hits of its own source, not how relevant it is, and the `score` member says the same: under a one-leg retrieval mode the first hit scores 1, and scores of sources searched in different modes are not comparable. The `objectstack-ai` skill lists `source.retrieval.mode` (vector, keyword or hybrid; omitted means the store's default; a mode the store does not run is refused at a run-time save, and a shipped source's every search answers 503), paid for by shortening two of its own sentences. diff --git a/content/docs/ai/knowledge-rag.mdx b/content/docs/ai/knowledge-rag.mdx index 9e88a9beea9..5e0223f82e4 100644 --- a/content/docs/ai/knowledge-rag.mdx +++ b/content/docs/ai/knowledge-rag.mdx @@ -131,13 +131,17 @@ hit's `title` is the value of the object's display field (`nameField`, else the derived title field). The two open stores, [pgvector](#self-hosted-vector-store-postgresql--pgvector) -and [libSQL](#local-vector-store-a-libsql-file), search with two legs: the -vector leg ranks by meaning, and a keyword leg ranks the passages that hold the -query's terms as written — an order number, a model code like `X-200`, a -person's name, a short term like 「出差」 — which a vector alone can rank -below `topK`. The two rankings are merged by reciprocal rank fusion, so a hit's -`score` is 1 for a passage first in both and 0.5 for one first in only one, and -the merge happens before the permission re-check. +and [libSQL](#local-vector-store-a-libsql-file), search with two legs by +default: the vector leg ranks by meaning, and a keyword leg ranks the passages +that hold the query's terms as written — an order number, a model code like +`X-200`, a person's name, a short term like 「出差」 — which a vector alone can +rank below `topK`. The two rankings are merged by reciprocal rank fusion, so a +hit's `score` is 1 for a passage first in both and 0.5 for one first in only +one, and the merge happens before the permission re-check. A source can run one +leg alone with `source.retrieval.mode` (`'vector'`, or `'keyword'`, which calls +no embedder); its first hit then scores 1. A score orders the hits of one +source; it is not a measure of relevance, and scores of two sources are not +comparable. ```ts const knowledge = ctx.getService('knowledge'); diff --git a/packages/services/service-knowledge/src/knowledge-tools.ts b/packages/services/service-knowledge/src/knowledge-tools.ts index 9cab070bb5a..83e4dbc2992 100644 --- a/packages/services/service-knowledge/src/knowledge-tools.ts +++ b/packages/services/service-knowledge/src/knowledge-tools.ts @@ -142,7 +142,12 @@ export interface SearchKnowledgeHit { title?: string; /** The passage that matched. */ snippet: string; - /** Relevance, higher is better. */ + /** + * The hit's order among the hits of its own source in the store's ranking: not a + * measure of relevance, and not comparable across sources (ADR-0161, the + * dated note of 2026-11-30 under K8). Under a one-leg mode it reflects rank + * alone, and the first hit scores 1. + */ score: number; /** The record the passage was indexed from: read it with the record tools. */ record?: { object: string; id: string }; @@ -222,7 +227,8 @@ const SEARCH_KNOWLEDGE_DESCRIPTION = 'Search the knowledge sources this app indexes (policies, manuals, articles, records indexed for retrieval) by ' + 'meaning, and answer with the most relevant passages, each naming its source and, for an indexed record, the ' + 'record it came from. Use it before answering a question the app\'s own documents or knowledge base should ' - + 'answer, and cite the passages you used. Send `query` as a short natural-language statement of what you are ' + + 'answer, and cite the passages you used. A hit\'s `score` says only its order among the hits of its own ' + + 'source, not how relevant it is. Send `query` as a short natural-language statement of what you are ' + 'looking for. Omit `sourceIds` to search every source; every answer lists the sources this tool may search, ' + 'and `sourceIds` takes their ids. `topK` caps the passages (default ' + `${SEARCH_KNOWLEDGE_DEFAULT_TOP_K}, at most ${SEARCH_KNOWLEDGE_MAX_TOP_K}). Only passages the caller may read ` diff --git a/scripts/check-skills-token-ratchet.mjs b/scripts/check-skills-token-ratchet.mjs index 95419ecaa85..a94d37689ff 100644 --- a/scripts/check-skills-token-ratchet.mjs +++ b/scripts/check-skills-token-ratchet.mjs @@ -564,7 +564,13 @@ export const CEILINGS = new Map([ // text is 28990 -> ceil(28990 / 4) = 7248; the row moves +48, the measured // remainder only. Pinned AT the measurement. // ceil(($(wc -c < skills/objectstack-ai/SKILL.md) - 27) / 4) == ceil(28990 / 4) - ['skills/objectstack-ai/SKILL.md', 7248], + // -1 (was 7248): #38692 phase 1a added the `source.retrieval.mode` row and + // paid for it in the same file: the `adapter` row's save refusal names the + // mounted stores alone, the one-slot sentence of the source's identity went + // (the registry's 409 names both doors), and "Rerank and hybrid weighting" + // became one clause. Banked at the measurement. + // ceil(($(wc -c < skills/objectstack-ai/SKILL.md) - 27) / 4) == ceil(28987 / 4) + ['skills/objectstack-ai/SKILL.md', 7247], // -12 (was 6331): the `http.server` decision-table row dropped a trailing // clause that taught `contributes.routes` as a key that "parses but serves // nothing". The key is retired — an authored entry is now REFUSED, carrying diff --git a/skills/objectstack-ai/SKILL.md b/skills/objectstack-ai/SKILL.md index 9ea69808248..3a153de575b 100644 --- a/skills/objectstack-ai/SKILL.md +++ b/skills/objectstack-ai/SKILL.md @@ -239,8 +239,7 @@ in `@objectstack/spec/ai`). Ship it in a package (`knowledgeSources`, `KnowledgeServicePlugin({ sources })` and `registerSource` are a second door for the same schema. A source is identified by its package and `name`; the ☁️ `search_knowledge` tool lists a package's source to agents as `NAMESPACE-NAME` -(bare for one no package holds), and a code registration and an environment -item of one name are one slot, the second refused. A shipped item mounts the +(bare for one no package holds). A shipped item mounts the knowledge service and its store; where an app ships none, a run-time save is refused (`503 SERVICE_UNAVAILABLE`, nothing written) until you add `requires: ['knowledge']` to the stack and restart the server. @@ -255,13 +254,14 @@ object or field, when you may not search that object or query a field it reads. |:----|:--------| | `name` | Snake_case source name | | `label` / `description` | Display metadata | -| `adapter` | Store id (`pgvector`, `turso`, `memory`). Omitted: the deployment's store (`pgvector` on PostgreSQL, `turso` otherwise), else the only one registered; several and none the deployment's is refused, naming them. A run-time save naming one the deployment does not mount is refused (`400 VALIDATION_ERROR`, nothing written), naming the source, the adapter and the mounted ones: name a mounted one, or mount the store and save again | +| `adapter` | Store id (`pgvector`, `turso`, `memory`). Omitted: the deployment's store (`pgvector` on PostgreSQL, `turso` otherwise), else the only one registered; several and none the deployment's is refused, naming them. A run-time save naming a store not mounted is refused (`400`), naming the mounted ones | | `source.kind` | `'object'`, the one kind | | `source.object` | The object whose records are indexed | | `source.content` | Non-empty list of the fields whose text is indexed, in order. `'*'` is refused: it would also send fields added later. Never ids or system fields | | `source.metadataFields` | Fields kept for search-time filtering (`status`, `owner_id`, `tags`) | | `source.where` | ObjectQL `where`: keeps drafts and archived rows out | | `source.split` | How documents are cut into passages (below) | +| `source.retrieval.mode` | `'vector'` (by meaning), `'keyword'` (by words: codes, clause numbers) or `'hybrid'`; omitted: the store's default (`hybrid` on `turso`, `pgvector`). A mode the store lacks fails a run-time save; shipped, every search (503). `memory` runs none | | `refresh.onRecordChange` | Sync from record events (default `true`); `false` leaves the index to an external indexer | | `aiExposed` | May `search_knowledge` expose it (default `true`) | @@ -347,8 +347,8 @@ Retired: the `knowledge.chunk_overlap` setting (`400 UNKNOWN_KEY`; passages never overlap) and `KnowledgeChunk.metadata` (parse error; a passage takes its document's `metadata`). -`topK` is a `search_knowledge` argument. Rerank and hybrid weighting are no -source key, and no shipped store has a setting for either. +`topK` is a `search_knowledge` argument; rerank and leg weights are no source +key. ---