Core without documents: no slugs; a node's top; targets by titles from the library root
The model has no slug any more (field, ops, canonical row, slugFor, freeSlug, RESERVED, findDoc). The child of the root a node is under is a derived relation, topOf (docOf and documents stay as deprecated aliases for the UI until step 2); ancestorsInDoc becomes ancestorsBelowRoot. Slug keys and a target's old `doc` in stored libraries are ignored. A node target's path is the titles down from the library root; `rel` marks a path read below a top (a file being imported, what the agent or a person typed). Where two sections share a title, the one the link is written in wins. The text format writes /Top title/…, and ./… inside the exported subtree. The agent may give a node id as a target. renderContext renders the top's outline in an <outline> tag, and steps down the focus path when even titles are over budget. Prompts, the reviewer and the scanner speak of the library, trees and tops; the scanner's unit is the top, with the same behaviour (scripts/linkEval.ts gives identical metrics). src/core/library.ts keeps a slug-free shim for the UI's document features (names made from titles) until step 2 removes them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
1 parent
626dc19e1b
commit
44d2e437eb
32 files changed
+634
-577
No files matched your search
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* The library's sections as vectors, for "closely matching nodes across documents": a VectorIndex
|
||||
* The library's sections as vectors, for "closely matching nodes under other tops": a VectorIndex
|
||||
* (server/embed.ts) of each section's title and text, kept current from the snapshot's patches.
|
||||
* A patch only marks the nodes it touched; they are re-embedded later, a batch at a time, off the
|
||||
* request that made the edit (a section whose text is unchanged is skipped by its hash). Without a
|
||||
* model the index still holds the texts, so BM25 search works and "related" is text-only.
|
||||
*/
|
||||
import { inArticles } from "../../src/core/article";
|
||||
import { Doc, docOf, isLibraryRoot, type NodeId, type Snap } from "../../src/core/model";
|
||||
import { Doc, isLibraryRoot, topOf, type NodeId, type Snap } from "../../src/core/model";
|
||||
import { plain } from "../../src/core/text";
|
||||
import { VectorIndex, type Embedder, type Hit, type HybridHit } from "../embed";
|
||||
|
||||
@@ -16,7 +16,7 @@ const nodeText = (snap: Snap, id: NodeId) => {
|
||||
return `${n.title}\n${plain(n.body)}`.trim();
|
||||
};
|
||||
|
||||
/** Sections (and documents) worth indexing: not the library root, not notes, not the Wikipedia container's, and with some text. */
|
||||
/** Sections (the root's children too) worth indexing: not the library root, not notes, not the Wikipedia container's, and with some text. */
|
||||
const indexable = (snap: Snap, id: NodeId) => {
|
||||
const n = snap.nodes[id];
|
||||
return !!n && n.kind === "section" && !isLibraryRoot(snap, id) && !inArticles(snap, id) && (n.body.trim().length > 0 || n.title.trim().length > 0);
|
||||
@@ -102,14 +102,14 @@ export class NodeIndex {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sections close in meaning to a text, from other documents, best first. Excludes the node, its
|
||||
* ancestors and its descendants. Null if there is no model.
|
||||
* Sections close in meaning to a text, from under other tops than `top`, best first. Excludes the
|
||||
* node, its ancestors and its descendants. Null if there is no model.
|
||||
*/
|
||||
async near(text: string, o: { exclude: Set<NodeId>; doc: NodeId | null; k?: number; snap: Snap; vector?: Float32Array | null }): Promise<Hit[] | null> {
|
||||
async near(text: string, o: { exclude: Set<NodeId>; top: NodeId | null; k?: number; snap: Snap; vector?: Float32Array | null }): Promise<Hit[] | null> {
|
||||
const k = o.k ?? 8;
|
||||
// Never built (a first start): build it now rather than answer from nothing.
|
||||
if (!this.vectors.size && (this.all || this.running)) await this.refresh();
|
||||
const filter = (id: string) => !o.exclude.has(id as NodeId) && !!o.snap.nodes[id as NodeId] && docOf(o.snap, id as NodeId) !== o.doc;
|
||||
const filter = (id: string) => !o.exclude.has(id as NodeId) && !!o.snap.nodes[id as NodeId] && topOf(o.snap, id as NodeId) !== o.top;
|
||||
if (o.vector) return this.vectors.searchVector(o.vector, k, filter);
|
||||
const v = await this.vectors.vector(text);
|
||||
return v ? this.vectors.searchVector(v, k, filter) : null;
|
||||
|
||||
Reference in new issue
Block a user