Skip to content

Commit 09eea10

Browse files
docs(knowledge): search_knowledge says what a score means; the AI skill lists source.retrieval.mode (#38732)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8QCBjsNDZa4iwo35VN5fKKg)_ Part of #38692 Clause-②: no Metadata-protocol: none ## 维护者速读 - AI 助手搜知识库时会被告知:分数只表示同一知识源内的先后,不表示相关程度;AI 作者文档写明了检索方式的用法。 - 属于知识管理专题「一期 a:检索方式」。 - 出错只会是说明文字不准,不影响搜索结果,可直接撤回。 - 无。 ## Stack Base: `main`. Stacked on the service PR #38722 (and through it #38720); until those merge, this diff carries their commits. Lands after both and after the phase-0 ADR note (#38714). ## What changes - `search_knowledge` description: one sentence, the ruling's 「分数只表示同一知识源内的先后,不表示相关程度」: "A hit's `score` says only its order among the hits of its own source, not how relevant it is." The `score` member's doc says the same, with the one-leg rule (first hit scores 1). - `skills/objectstack-ai/SKILL.md`: a `source.retrieval.mode` row in the knowledge source key table; paid for in the same file (the `adapter` row's save refusal shortened, the one-slot sentence dropped, the closing rerank line made one clause and no longer says "hybrid weighting"). The row says an unsupported mode fails a run-time save and, for a shipped source, every search (503). Ratchet row lowered 7248 → 7247. - `content/docs/ai/knowledge-rag.mdx`: the "0.5 for one first in only one" paragraph now says a source can run one leg alone, its first hit then scores 1, and scores order one source's hits only. - Patch changeset, naming `@objectstack/service-knowledge` and `@objectstack/skills` (which ships the SKILL.md). ## Tests - `service-knowledge`: 860 passed (no test pins the description text). - Skill gates: token ratchet, links, identifier liveness, frame sync and freshness, top-level keys, affected docs: all green. ## Acceptance notes Skill readings (`skills/**` touched): | | before | after | |:--|--:|--:| | `skills/objectstack-ai/SKILL.md` lines | 507 | 507 | | `skills/objectstack-ai/SKILL.md` bytes / tokens | 29017 / 7248 | 28990 / 7241 | | all `skills/*/SKILL.md` lines | 3406 | 3406 | | all `skills/*/SKILL.md` bytes | 180659 | 180632 | Net growth zero: the new row is paid by deletion in the same file. ## Verification - Two-minute check: `node scripts/check-skills-token-ratchet.mjs` → green, `objectstack-ai/SKILL.md` 7241 / 7241. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [ ] 4. One issue, one branch off an up-to-date `main`, one pull request. (Stacked: see "Stack" above.) - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: its generated artifacts are regenerated and committed. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01JQwxbaASqBozmmj1n5tbUf <!-- signed: repo:objectstack#2 · os-warren · session_01JQwxbaASqBozmmj1n5tbUf --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c8b1dbb commit 09eea10

5 files changed

Lines changed: 42 additions & 15 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@objectstack/service-knowledge': patch
3+
'@objectstack/skills': patch
4+
---
5+
6+
docs(knowledge): `search_knowledge` says what a hit's score means, and the AI skill documents `source.retrieval.mode`
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
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.

‎content/docs/ai/knowledge-rag.mdx‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,17 @@ hit's `title` is the value of the object's display field (`nameField`, else the
131131
derived title field).
132132

133133
The two open stores, [pgvector](#self-hosted-vector-store-postgresql--pgvector)
134-
and [libSQL](#local-vector-store-a-libsql-file), search with two legs: the
135-
vector leg ranks by meaning, and a keyword leg ranks the passages that hold the
136-
query's terms as written — an order number, a model code like `X-200`, a
137-
person's name, a short term like 「出差」 — which a vector alone can rank
138-
below `topK`. The two rankings are merged by reciprocal rank fusion, so a hit's
139-
`score` is 1 for a passage first in both and 0.5 for one first in only one, and
140-
the merge happens before the permission re-check.
134+
and [libSQL](#local-vector-store-a-libsql-file), search with two legs by
135+
default: the vector leg ranks by meaning, and a keyword leg ranks the passages
136+
that hold the query's terms as written — an order number, a model code like
137+
`X-200`, a person's name, a short term like 「出差」 — which a vector alone can
138+
rank below `topK`. The two rankings are merged by reciprocal rank fusion, so a
139+
hit's `score` is 1 for a passage first in both and 0.5 for one first in only
140+
one, and the merge happens before the permission re-check. A source can run one
141+
leg alone with `source.retrieval.mode` (`'vector'`, or `'keyword'`, which calls
142+
no embedder); its first hit then scores 1. A score orders the hits of one
143+
source; it is not a measure of relevance, and scores of two sources are not
144+
comparable.
141145

142146
```ts
143147
const knowledge = ctx.getService('knowledge');

‎packages/services/service-knowledge/src/knowledge-tools.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ export interface SearchKnowledgeHit {
142142
title?: string;
143143
/** The passage that matched. */
144144
snippet: string;
145-
/** Relevance, higher is better. */
145+
/**
146+
* The hit's order among the hits of its own source in the store's ranking: not a
147+
* measure of relevance, and not comparable across sources (ADR-0161, the
148+
* dated note of 2026-11-30 under K8). Under a one-leg mode it reflects rank
149+
* alone, and the first hit scores 1.
150+
*/
146151
score: number;
147152
/** The record the passage was indexed from: read it with the record tools. */
148153
record?: { object: string; id: string };
@@ -226,7 +231,8 @@ const SEARCH_KNOWLEDGE_DESCRIPTION =
226231
'Search the knowledge sources this app indexes (policies, manuals, articles, records indexed for retrieval) by '
227232
+ 'meaning, and answer with the most relevant passages, each naming its source and, for an indexed record, the '
228233
+ 'record it came from. Use it before answering a question the app\'s own documents or knowledge base should '
229-
+ 'answer, and cite the passages you used. Send `query` as a short natural-language statement of what you are '
234+
+ 'answer, and cite the passages you used. A hit\'s `score` says only its order among the hits of its own '
235+
+ 'source, not how relevant it is. Send `query` as a short natural-language statement of what you are '
230236
+ 'looking for. Omit `sourceIds` to search every source; every answer lists the sources this tool may search, '
231237
+ 'and `sourceIds` takes their ids. `topK` caps the passages (default '
232238
+ `${SEARCH_KNOWLEDGE_DEFAULT_TOP_K}, at most ${SEARCH_KNOWLEDGE_MAX_TOP_K}). Only passages the caller may read `

‎scripts/check-skills-token-ratchet.mjs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,13 @@ export const CEILINGS = new Map([
564564
// text is 28990 -> ceil(28990 / 4) = 7248; the row moves +48, the measured
565565
// remainder only. Pinned AT the measurement.
566566
// ceil(($(wc -c < skills/objectstack-ai/SKILL.md) - 27) / 4) == ceil(28990 / 4)
567-
['skills/objectstack-ai/SKILL.md', 7248],
567+
// -1 (was 7248): #38692 phase 1a added the `source.retrieval.mode` row and
568+
// paid for it in the same file: the `adapter` row's save refusal names the
569+
// mounted stores alone, the one-slot sentence of the source's identity went
570+
// (the registry's 409 names both doors), and "Rerank and hybrid weighting"
571+
// became one clause. Banked at the measurement.
572+
// ceil(($(wc -c < skills/objectstack-ai/SKILL.md) - 27) / 4) == ceil(28987 / 4)
573+
['skills/objectstack-ai/SKILL.md', 7247],
568574
// -12 (was 6331): the `http.server` decision-table row dropped a trailing
569575
// clause that taught `contributes.routes` as a key that "parses but serves
570576
// nothing". The key is retired — an authored entry is now REFUSED, carrying

‎skills/objectstack-ai/SKILL.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ in `@objectstack/spec/ai`). Ship it in a package (`knowledgeSources`,
239239
`KnowledgeServicePlugin({ sources })` and `registerSource` are a second door for
240240
the same schema. A source is identified by its package and `name`; the ☁️
241241
`search_knowledge` tool lists a package's source to agents as `NAMESPACE-NAME`
242-
(bare for one no package holds), and a code registration and an environment
243-
item of one name are one slot, the second refused. A shipped item mounts the
242+
(bare for one no package holds). A shipped item mounts the
244243
knowledge service and its store; where an app ships none, a run-time save is
245244
refused (`503 SERVICE_UNAVAILABLE`, nothing written) until you add
246245
`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.
255254
|:----|:--------|
256255
| `name` | Snake_case source name |
257256
| `label` / `description` | Display metadata |
258-
| `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 |
257+
| `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 |
259258
| `source.kind` | `'object'`, the one kind |
260259
| `source.object` | The object whose records are indexed |
261260
| `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 |
262261
| `source.metadataFields` | Fields kept for search-time filtering (`status`, `owner_id`, `tags`) |
263262
| `source.where` | ObjectQL `where`: keeps drafts and archived rows out |
264263
| `source.split` | How documents are cut into passages (below) |
264+
| `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 |
265265
| `refresh.onRecordChange` | Sync from record events (default `true`); `false` leaves the index to an external indexer |
266266
| `aiExposed` | May `search_knowledge` expose it (default `true`) |
267267

@@ -347,8 +347,8 @@ Retired: the `knowledge.chunk_overlap` setting (`400 UNKNOWN_KEY`;
347347
passages never overlap) and `KnowledgeChunk.metadata` (parse error; a passage
348348
takes its document's `metadata`).
349349

350-
`topK` is a `search_knowledge` argument. Rerank and hybrid weighting are no
351-
source key, and no shipped store has a setting for either.
350+
`topK` is a `search_knowledge` argument; rerank and leg weights are no source
351+
key.
352352

353353
---
354354

0 commit comments

Comments
 (0)