@yaks/embedding 0.0.0-stage → 0.2.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +549 -2
- package/_dist/compile.d.ts +34 -0
- package/_dist/compile.d.ts.map +1 -0
- package/_dist/ddl.d.ts +31 -0
- package/_dist/ddl.d.ts.map +1 -0
- package/_dist/embedder.d.ts +55 -0
- package/_dist/embedder.d.ts.map +1 -0
- package/_dist/fields.d.ts +70 -0
- package/_dist/fields.d.ts.map +1 -0
- package/_dist/graph.d.ts +63 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/held.d.ts +16 -0
- package/_dist/held.d.ts.map +1 -0
- package/_dist/image.d.ts +20 -0
- package/_dist/image.d.ts.map +1 -0
- package/_dist/mod.d.ts +105 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/native.d.ts +20 -0
- package/_dist/native.d.ts.map +1 -0
- package/_dist/near.d.ts +35 -0
- package/_dist/near.d.ts.map +1 -0
- package/_dist/neighbours.d.ts +29 -0
- package/_dist/neighbours.d.ts.map +1 -0
- package/_dist/options.d.ts +37 -0
- package/_dist/options.d.ts.map +1 -0
- package/_dist/outage.d.ts +64 -0
- package/_dist/outage.d.ts.map +1 -0
- package/_dist/owed.d.ts +79 -0
- package/_dist/owed.d.ts.map +1 -0
- package/_dist/remote.d.ts +116 -0
- package/_dist/remote.d.ts.map +1 -0
- package/_dist/score.d.ts +10 -0
- package/_dist/score.d.ts.map +1 -0
- package/_dist/search.d.ts +24 -0
- package/_dist/search.d.ts.map +1 -0
- package/_dist/service.d.ts +23 -0
- package/_dist/service.d.ts.map +1 -0
- package/_dist/sleeper.d.ts +37 -0
- package/_dist/sleeper.d.ts.map +1 -0
- package/_dist/sweep.d.ts +71 -0
- package/_dist/sweep.d.ts.map +1 -0
- package/_dist/tools.d.ts +14 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/vector.d.ts +30 -0
- package/_dist/vector.d.ts.map +1 -0
- package/_dist/vocab.d.ts +6 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/coded.js +98 -0
- package/coded.js.map +1 -0
- package/coded.ts +85 -0
- package/compile.js +145 -0
- package/compile.js.map +1 -0
- package/compile.ts +206 -0
- package/ddl.js +476 -0
- package/ddl.js.map +1 -0
- package/ddl.ts +346 -0
- package/deno.json +1 -0
- package/embedder.js +85 -0
- package/embedder.js.map +1 -0
- package/embedder.ts +113 -0
- package/fields.js +178 -0
- package/fields.js.map +1 -0
- package/fields.ts +259 -0
- package/fill.js +177 -0
- package/fill.js.map +1 -0
- package/fill.ts +144 -0
- package/graph.js +113 -0
- package/graph.js.map +1 -0
- package/graph.ts +167 -0
- package/held.js +680 -0
- package/held.js.map +1 -0
- package/held.ts +726 -0
- package/image.js +202 -0
- package/image.js.map +1 -0
- package/image.ts +185 -0
- package/mod.js +105 -0
- package/mod.js.map +1 -0
- package/mod.ts +113 -0
- package/native.js +236 -0
- package/native.js.map +1 -0
- package/native.ts +288 -0
- package/near.js +123 -0
- package/near.js.map +1 -0
- package/near.ts +192 -0
- package/neighbours.js +223 -0
- package/neighbours.js.map +1 -0
- package/neighbours.ts +303 -0
- package/options.js +187 -0
- package/options.js.map +1 -0
- package/options.ts +269 -0
- package/outage.js +128 -0
- package/outage.js.map +1 -0
- package/outage.ts +132 -0
- package/owed.js +287 -0
- package/owed.js.map +1 -0
- package/owed.ts +346 -0
- package/package.json +45 -4
- package/remote.js +264 -0
- package/remote.js.map +1 -0
- package/remote.ts +391 -0
- package/score.js +46 -0
- package/score.js.map +1 -0
- package/score.ts +60 -0
- package/search.js +65 -0
- package/search.js.map +1 -0
- package/search.ts +118 -0
- package/service.js +107 -0
- package/service.js.map +1 -0
- package/service.ts +133 -0
- package/sleeper.js +107 -0
- package/sleeper.js.map +1 -0
- package/sleeper.ts +166 -0
- package/sparse.js +36 -0
- package/sparse.js.map +1 -0
- package/sparse.ts +49 -0
- package/sweep.js +374 -0
- package/sweep.js.map +1 -0
- package/sweep.ts +446 -0
- package/tools.js +57 -0
- package/tools.js.map +1 -0
- package/tools.ts +88 -0
- package/vector.js +78 -0
- package/vector.js.map +1 -0
- package/vector.ts +96 -0
- package/visibility.js +83 -0
- package/visibility.js.map +1 -0
- package/visibility.ts +111 -0
- package/vocab.js +22 -0
- package/vocab.js.map +1 -0
- package/vocab.json +19 -0
- package/vocab.ts +22 -0
package/vector.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// The vectors themselves: how one is stored, read back, and compared.
|
|
2
|
+
//
|
|
3
|
+
// A vector is a `Float32Array`. The store holds its raw bytes as a blob, so the
|
|
4
|
+
// dimension is the blob's byte length over four and no column has to carry it —
|
|
5
|
+
// and a vector from a different model, with a different dimension, is refused by
|
|
6
|
+
// arithmetic rather than by bookkeeping.
|
|
7
|
+
//
|
|
8
|
+
// Comparison is cosine similarity: 1 identical, 0 unrelated, negative opposed.
|
|
9
|
+
// For unit-length vectors that is just the dot product, and everything stored
|
|
10
|
+
// here is normalized on the way in, so ranking a corpus is one multiply-add
|
|
11
|
+
// pass per vector.
|
|
12
|
+
|
|
13
|
+
/** A vector's raw bytes, for storing it as a blob. */
|
|
14
|
+
export let pack = (v: Float32Array): Uint8Array =>
|
|
15
|
+
new Uint8Array(v.buffer.slice(v.byteOffset, v.byteOffset + v.byteLength))
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A vector read back from its blob. The copy is deliberate: a `Float32Array`
|
|
19
|
+
* needs a 4-byte-aligned buffer, and bytes handed back by a driver are aligned
|
|
20
|
+
* only by luck.
|
|
21
|
+
*/
|
|
22
|
+
export let unpack = (bytes: Uint8Array): Float32Array =>
|
|
23
|
+
new Float32Array(bytes.slice().buffer)
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A vector read back from its blob without a copy where it can be: a view of
|
|
27
|
+
* the bytes where they are 4-byte aligned, {@link unpack}'s copy where not.
|
|
28
|
+
* The view shares the bytes, so it is for reading.
|
|
29
|
+
*/
|
|
30
|
+
export let floats = (bytes: Uint8Array): Float32Array =>
|
|
31
|
+
bytes.byteOffset % 4 == 0
|
|
32
|
+
? new Float32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4)
|
|
33
|
+
: unpack(bytes)
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The same direction at length 1. A zero vector has no direction, so it comes
|
|
37
|
+
* back unchanged — {@link cosine} answers 0 against it, which is what "unrelated
|
|
38
|
+
* to everything" should read as.
|
|
39
|
+
*/
|
|
40
|
+
export let unit = (v: Float32Array): Float32Array => {
|
|
41
|
+
let sum = 0
|
|
42
|
+
for (let x of v) sum += x * x
|
|
43
|
+
let len = Math.sqrt(sum)
|
|
44
|
+
if (!len) return v
|
|
45
|
+
let out = new Float32Array(v.length)
|
|
46
|
+
for (let i = 0; i < v.length; i++) out[i] = v[i] / len
|
|
47
|
+
return out
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Cosine similarity, 1 for the same direction and 0 for unrelated. Two vectors
|
|
52
|
+
* of different lengths are from different spaces and score 0 — a model change
|
|
53
|
+
* makes every old vector unrelated rather than subtly wrong.
|
|
54
|
+
*/
|
|
55
|
+
export let cosine = (a: Float32Array, b: Float32Array | Int8Array): number => {
|
|
56
|
+
if (a.length != b.length) return 0
|
|
57
|
+
let dot = 0, la = 0, lb = 0
|
|
58
|
+
for (let i = 0; i < a.length; i++) {
|
|
59
|
+
dot += a[i] * b[i]
|
|
60
|
+
la += a[i] * a[i]
|
|
61
|
+
lb += b[i] * b[i]
|
|
62
|
+
}
|
|
63
|
+
let len = Math.sqrt(la) * Math.sqrt(lb)
|
|
64
|
+
return len ? dot / len : 0
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Code `v` into `codes` from `at`: each coordinate over the largest, rounded
|
|
69
|
+
* to one of 255 steps from -127 to 127. Returns the scale that turns the
|
|
70
|
+
* codes' dot product with a query back into cosine times the query's length;
|
|
71
|
+
* 0 for a vector with no direction. The codes alone keep the direction, so
|
|
72
|
+
* their cosine is the vector's, give or take a step.
|
|
73
|
+
*/
|
|
74
|
+
export let code = (v: Float32Array, codes: Int8Array, at = 0): number => {
|
|
75
|
+
let max = 0, sum = 0, dim = v.length
|
|
76
|
+
for (let j = 0; j < dim; j++) {
|
|
77
|
+
let x = v[j]
|
|
78
|
+
sum += x * x
|
|
79
|
+
if (x > max) max = x
|
|
80
|
+
else if (-x > max) max = -x
|
|
81
|
+
}
|
|
82
|
+
if (!max) {
|
|
83
|
+
codes.fill(0, at, at + dim)
|
|
84
|
+
return 0
|
|
85
|
+
}
|
|
86
|
+
let k = 127 / max
|
|
87
|
+
for (let j = 0; j < dim; j++) codes[at + j] = Math.round(v[j] * k)
|
|
88
|
+
return max / 127 / Math.sqrt(sum)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** A vector's int8 codes as a blob, the shape a native int8 scan reads. */
|
|
92
|
+
export let coded = (v: Float32Array): Uint8Array => {
|
|
93
|
+
let codes = new Int8Array(v.length)
|
|
94
|
+
code(v, codes)
|
|
95
|
+
return new Uint8Array(codes.buffer)
|
|
96
|
+
}
|
package/visibility.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// An entity's vector contains all its embedded text. A reader may use it
|
|
2
|
+
// only when every contributing aspect is visible, including a query anchor.
|
|
3
|
+
//
|
|
4
|
+
// A screen here admits nearly every entity in the graph, so it is only ever
|
|
5
|
+
// asked about one id at a time (./native.ts `admitted`), never read whole:
|
|
6
|
+
// `id in (screen)` makes SQLite list every visible entity first, seconds on a
|
|
7
|
+
// graph of millions, while a correlated test reaches each id by its key.
|
|
8
|
+
import { among, and, col, from, not, render, select, sourceScreen, table } from "@yaks/sql";
|
|
9
|
+
import { OWED } from "./ddl.js";
|
|
10
|
+
import { allowed, pieces } from "./fields.js";
|
|
11
|
+
import { admitted } from "./native.js";
|
|
12
|
+
/** Owner ids whose stored vectors contain no hidden source text. A pending
|
|
13
|
+
* vector is excluded while a component policy applies: after a private
|
|
14
|
+
* source is removed, its old vector still holds that text until the sweep. */ export let visibleVectors = (vocab, fields, visibility, absent)=>{
|
|
15
|
+
if (!visibility || !visibility.entity && !Object.keys(visibility.components ?? {}).length) return undefined;
|
|
16
|
+
// A policy naming a component no table stands for reads it as worn by
|
|
17
|
+
// nobody (@yaks/sql `absent`).
|
|
18
|
+
let opts = {
|
|
19
|
+
visibility,
|
|
20
|
+
absent
|
|
21
|
+
};
|
|
22
|
+
let entity = sourceScreen(vocab, opts);
|
|
23
|
+
let restricted = fields.filter((f)=>visibility.components?.[f.comp] || f.on && visibility.components?.[f.on]);
|
|
24
|
+
let scopes = new Map();
|
|
25
|
+
let permission = (f)=>{
|
|
26
|
+
let comps = [
|
|
27
|
+
f.comp,
|
|
28
|
+
...f.on ? [
|
|
29
|
+
f.on
|
|
30
|
+
] : []
|
|
31
|
+
];
|
|
32
|
+
let key = JSON.stringify(comps);
|
|
33
|
+
if (!scopes.has(key)) {
|
|
34
|
+
scopes.set(key, sourceScreen(vocab, {
|
|
35
|
+
visibility: {
|
|
36
|
+
components: visibility.components
|
|
37
|
+
},
|
|
38
|
+
absent
|
|
39
|
+
}, comps));
|
|
40
|
+
}
|
|
41
|
+
return scopes.get(key);
|
|
42
|
+
};
|
|
43
|
+
let hidden = pieces(restricted.filter(permission), undefined, undefined, (f)=>[
|
|
44
|
+
...allowed(f),
|
|
45
|
+
not(admitted(permission(f), col('entity', 'c')))
|
|
46
|
+
]);
|
|
47
|
+
if (!restricted.length && !Object.keys(visibility.components ?? {}).length) {
|
|
48
|
+
return entity ?? undefined;
|
|
49
|
+
}
|
|
50
|
+
let id = col('id', 'v');
|
|
51
|
+
return render(select({
|
|
52
|
+
cols: [
|
|
53
|
+
id
|
|
54
|
+
],
|
|
55
|
+
from: table('entity', 'v'),
|
|
56
|
+
where: and(...entity ? [
|
|
57
|
+
admitted(entity, id)
|
|
58
|
+
] : [], ...hidden.map((q)=>not(among(id, select({
|
|
59
|
+
cols: [
|
|
60
|
+
col('owner', 'h')
|
|
61
|
+
],
|
|
62
|
+
from: from(q, 'h')
|
|
63
|
+
})))), ...Object.keys(visibility.components ?? {}).length ? [
|
|
64
|
+
not(among(id, select({
|
|
65
|
+
cols: [
|
|
66
|
+
col('owner')
|
|
67
|
+
],
|
|
68
|
+
from: table(OWED)
|
|
69
|
+
})))
|
|
70
|
+
] : [])
|
|
71
|
+
}));
|
|
72
|
+
};
|
|
73
|
+
/** Combine independent owner selections before a ranking is cut. */ export let screened = (within, visible)=>visible && within ? {
|
|
74
|
+
...render(select({
|
|
75
|
+
cols: [
|
|
76
|
+
col('id', 'w')
|
|
77
|
+
],
|
|
78
|
+
from: from(within, 'w'),
|
|
79
|
+
where: admitted(visible, col('id', 'w'))
|
|
80
|
+
})),
|
|
81
|
+
probe: (owner)=>and(admitted(within, owner), admitted(visible, owner))
|
|
82
|
+
} : visible ?? within ?? undefined;
|
|
83
|
+
//# sourceMappingURL=visibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visibility.js","sources":["./visibility.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,4EAA4E;AAC5E,EAAE;AACF,4EAA4E;AAC5E,2EAA2E;AAC3E,8EAA8E;AAC9E,yEAAyE;AACzE,SACE,KAAK,EACL,GAAG,EAEH,GAAG,EACH,IAAI,EACJ,GAAG,EAEH,MAAM,EACN,MAAM,EAEN,YAAY,EACZ,KAAK,yBACsB;AAE7B,SAAS,IAAI,mBAAkB;AAC/B,SAAS,OAAO,EAAc,MAAM,sBAAqB;AACzD,SAAS,QAAQ,sBAAqB;AAEtC;;4EAE4E,GAC5E,OAAO,IAAI,iBAAiB,CAC1B,OACA,QACA,YACA;EAEA,IACE,CAAC,cACD,CAAC,WAAW,MAAM,IAAI,CAAC,OAAO,IAAI,CAAC,WAAW,UAAU,IAAI,CAAC,GAAG,MAAM,EACtE,OAAO;EACT,sEAAsE;EACtE,+BAA+B;EAC/B,IAAI,OAAO;IAAE;IAAY;EAAO;EAChC,IAAI,SAAS,aAAa,OAAO;EACjC,IAAI,aAAa,OAAO,MAAM,CAAC,CAAC,IAC9B,WAAW,UAAU,EAAE,CAAC,EAAE,IAAI,CAAC,IAC/B,EAAE,EAAE,IAAI,WAAW,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC;EAEvC,IAAI,SAAS,IAAI;EACjB,IAAI,aAAa,CAAC;IAChB,IAAI,QAAQ;MAAC,EAAE,IAAI;SAAK,EAAE,EAAE,GAAG;QAAC,EAAE,EAAE;OAAC,GAAG,EAAE;KAAC;IAC3C,IAAI,MAAM,KAAK,SAAS,CAAC;IACzB,IAAI,CAAC,OAAO,GAAG,CAAC,MAAM;MACpB,OAAO,GAAG,CACR,KACA,aAAa,OAAO;QAClB,YAAY;UAAE,YAAY,WAAW,UAAU;QAAC;QAChD;MACF,GAAG;IAEP;IACA,OAAO,OAAO,GAAG,CAAC;EACpB;EACA,IAAI,SAAS,OACX,WAAW,MAAM,CAAC,aAClB,WACA,WACA,CAAC,IAAM;SACF,QAAQ;MACX,IAAI,SAAS,WAAW,IAAK,IAAI,UAAU;KAC5C;EAEH,IAAI,CAAC,WAAW,MAAM,IAAI,CAAC,OAAO,IAAI,CAAC,WAAW,UAAU,IAAI,CAAC,GAAG,MAAM,EAAE;IAC1E,OAAO,UAAU;EACnB;EACA,IAAI,KAAK,IAAI,MAAM;EACnB,OAAO,OAAO,OAAO;IACnB,MAAM;MAAC;KAAG;IACV,MAAM,MAAM,UAAU;IACtB,OAAO,OACF,SAAS;MAAC,SAAS,QAAQ;KAAI,GAAG,EAAE,KACpC,OAAO,GAAG,CAAC,CAAC,IACb,IAAI,MACF,IACA,OAAO;QACL,MAAM;UAAC,IAAI,SAAS;SAAK;QACzB,MAAM,KAAK,GAAG;MAChB,UAGD,OAAO,IAAI,CAAC,WAAW,UAAU,IAAI,CAAC,GAAG,MAAM,GAC9C;MAAC,IAAI,MAAM,IAAI,OAAO;QAAE,MAAM;UAAC,IAAI;SAAS;QAAE,MAAM,MAAM;MAAM;KAAK,GACrE,EAAE;EAEV;AACF,EAAC;AAED,kEAAkE,GAClE,OAAO,IAAI,WAAW,CACpB,QACA,UAEA,WAAW,SACP;IACA,GAAG,OAAO,OAAO;MACf,MAAM;QAAC,IAAI,MAAM;OAAK;MACtB,MAAM,KAAK,QAAQ;MACnB,OAAO,SAAS,SAAS,IAAI,MAAM;IACrC,GAAG;IACH,OAAO,CAAC,QAAU,IAAI,SAAS,QAAQ,QAAQ,SAAS,SAAS;EACnE,IACE,WAAW,UAAU,UAAS"}
|
package/visibility.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// An entity's vector contains all its embedded text. A reader may use it
|
|
2
|
+
// only when every contributing aspect is visible, including a query anchor.
|
|
3
|
+
//
|
|
4
|
+
// A screen here admits nearly every entity in the graph, so it is only ever
|
|
5
|
+
// asked about one id at a time (./native.ts `admitted`), never read whole:
|
|
6
|
+
// `id in (screen)` makes SQLite list every visible entity first, seconds on a
|
|
7
|
+
// graph of millions, while a correlated test reaches each id by its key.
|
|
8
|
+
import {
|
|
9
|
+
among,
|
|
10
|
+
and,
|
|
11
|
+
type BindOpts,
|
|
12
|
+
col,
|
|
13
|
+
from,
|
|
14
|
+
not,
|
|
15
|
+
type Raw,
|
|
16
|
+
render,
|
|
17
|
+
select,
|
|
18
|
+
type Selection,
|
|
19
|
+
sourceScreen,
|
|
20
|
+
table,
|
|
21
|
+
} from '@yaks/sql'
|
|
22
|
+
import type { Vocab } from 'jsr:@yaks/vocab@0.2.36'
|
|
23
|
+
import { OWED } from './ddl.js'
|
|
24
|
+
import { allowed, type Field, pieces } from './fields.js'
|
|
25
|
+
import { admitted } from './native.js'
|
|
26
|
+
|
|
27
|
+
/** Owner ids whose stored vectors contain no hidden source text. A pending
|
|
28
|
+
* vector is excluded while a component policy applies: after a private
|
|
29
|
+
* source is removed, its old vector still holds that text until the sweep. */
|
|
30
|
+
export let visibleVectors = (
|
|
31
|
+
vocab: Vocab,
|
|
32
|
+
fields: Field[],
|
|
33
|
+
visibility?: BindOpts['visibility'],
|
|
34
|
+
absent?: BindOpts['absent'],
|
|
35
|
+
): Raw | undefined => {
|
|
36
|
+
if (
|
|
37
|
+
!visibility ||
|
|
38
|
+
!visibility.entity && !Object.keys(visibility.components ?? {}).length
|
|
39
|
+
) return undefined
|
|
40
|
+
// A policy naming a component no table stands for reads it as worn by
|
|
41
|
+
// nobody (@yaks/sql `absent`).
|
|
42
|
+
let opts = { visibility, absent }
|
|
43
|
+
let entity = sourceScreen(vocab, opts)
|
|
44
|
+
let restricted = fields.filter((f) =>
|
|
45
|
+
visibility.components?.[f.comp] ||
|
|
46
|
+
f.on && visibility.components?.[f.on]
|
|
47
|
+
)
|
|
48
|
+
let scopes = new Map<string, Raw | null>()
|
|
49
|
+
let permission = (f: Field) => {
|
|
50
|
+
let comps = [f.comp, ...f.on ? [f.on] : []]
|
|
51
|
+
let key = JSON.stringify(comps)
|
|
52
|
+
if (!scopes.has(key)) {
|
|
53
|
+
scopes.set(
|
|
54
|
+
key,
|
|
55
|
+
sourceScreen(vocab, {
|
|
56
|
+
visibility: { components: visibility.components },
|
|
57
|
+
absent,
|
|
58
|
+
}, comps),
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
return scopes.get(key)
|
|
62
|
+
}
|
|
63
|
+
let hidden = pieces(
|
|
64
|
+
restricted.filter(permission),
|
|
65
|
+
undefined,
|
|
66
|
+
undefined,
|
|
67
|
+
(f) => [
|
|
68
|
+
...allowed(f),
|
|
69
|
+
not(admitted(permission(f)!, col('entity', 'c'))),
|
|
70
|
+
],
|
|
71
|
+
)
|
|
72
|
+
if (!restricted.length && !Object.keys(visibility.components ?? {}).length) {
|
|
73
|
+
return entity ?? undefined
|
|
74
|
+
}
|
|
75
|
+
let id = col('id', 'v')
|
|
76
|
+
return render(select({
|
|
77
|
+
cols: [id],
|
|
78
|
+
from: table('entity', 'v'),
|
|
79
|
+
where: and(
|
|
80
|
+
...entity ? [admitted(entity, id)] : [],
|
|
81
|
+
...hidden.map((q) =>
|
|
82
|
+
not(among(
|
|
83
|
+
id,
|
|
84
|
+
select({
|
|
85
|
+
cols: [col('owner', 'h')],
|
|
86
|
+
from: from(q, 'h'),
|
|
87
|
+
}),
|
|
88
|
+
))
|
|
89
|
+
),
|
|
90
|
+
...Object.keys(visibility.components ?? {}).length
|
|
91
|
+
? [not(among(id, select({ cols: [col('owner')], from: table(OWED) })))]
|
|
92
|
+
: [],
|
|
93
|
+
),
|
|
94
|
+
}))
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Combine independent owner selections before a ranking is cut. */
|
|
98
|
+
export let screened = (
|
|
99
|
+
within?: Selection | null,
|
|
100
|
+
visible?: Selection,
|
|
101
|
+
): Selection | undefined =>
|
|
102
|
+
visible && within
|
|
103
|
+
? {
|
|
104
|
+
...render(select({
|
|
105
|
+
cols: [col('id', 'w')],
|
|
106
|
+
from: from(within, 'w'),
|
|
107
|
+
where: admitted(visible, col('id', 'w')),
|
|
108
|
+
})),
|
|
109
|
+
probe: (owner) => and(admitted(within, owner), admitted(visible, owner)),
|
|
110
|
+
}
|
|
111
|
+
: visible ?? within ?? undefined
|
package/vocab.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// The vocabulary this package contributes, and nothing else
|
|
2
|
+
// (`@yaks/embedding/vocab`). It declares no component — no client ever writes
|
|
3
|
+
// a vector: it is derived from text another package's vocabulary declares, it
|
|
4
|
+
// is never sent to a client, and no patch creates one, which is why the table
|
|
5
|
+
// is created in SQL by ./graph.ts.
|
|
6
|
+
//
|
|
7
|
+
// What it does declare is one tool: the check in ./tools.ts. A tool is
|
|
8
|
+
// declared in a vocabulary and listed by the server, so the index's own
|
|
9
|
+
// invariant can be asked about the same way every other package's is.
|
|
10
|
+
import doc from './vocab.json' with {
|
|
11
|
+
type: 'json'
|
|
12
|
+
};
|
|
13
|
+
import manifest from './package.json' with {
|
|
14
|
+
type: 'json'
|
|
15
|
+
};
|
|
16
|
+
/** The tool declaration this plugin contributes. */ export let embeddingDoc = doc;
|
|
17
|
+
/** What this package is: its manifest's description, the one place it is
|
|
18
|
+
* written, which a host stamps on each document here. */ export let description = manifest.description;
|
|
19
|
+
/** Every document this plugin declares. */ export let docs = [
|
|
20
|
+
embeddingDoc
|
|
21
|
+
];
|
|
22
|
+
//# sourceMappingURL=vocab.js.map
|
package/vocab.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocab.js","sources":["./vocab.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,8EAA8E;AAC9E,8EAA8E;AAC9E,8EAA8E;AAC9E,mCAAmC;AACnC,EAAE;AACF,uEAAuE;AACvE,wEAAwE;AACxE,sEAAsE;AAEtE,OAAO,SAAS,oBAAoB;EAAE,MAAM;AAAO,EAAC;AACpD,OAAO,cAAc,sBAAsB;EAAE,MAAM;AAAO,EAAC;AAE3D,kDAAkD,GAClD,OAAO,IAAI,eAAyB,IAAG;AAEvC;uDACuD,GACvD,OAAO,IAAI,cAAsB,SAAS,WAAW,CAAA;AAErD,yCAAyC,GACzC,OAAO,IAAI,OAAmB;EAAC;CAAa,CAAA"}
|
package/vocab.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$id": "urn:uuid:67c4b537-be1d-400e-bc0f-9ba3f59477fd",
|
|
3
|
+
"$vocabulary": {
|
|
4
|
+
"https://yak.sh/vocab/core": true
|
|
5
|
+
},
|
|
6
|
+
"title": "embedding",
|
|
7
|
+
"instructions": "A tool call that creates something is answered with the nearest few existing entities of its kind, each a `hit` whose `near` names the new one. When one of them is the same thing, keep the one that stands: update it, and delete the new one.",
|
|
8
|
+
"$defs": {
|
|
9
|
+
"vector_check": {
|
|
10
|
+
"tool": true,
|
|
11
|
+
"noun": "vector",
|
|
12
|
+
"verb": "check",
|
|
13
|
+
"title": "Check stored vectors",
|
|
14
|
+
"description": "Check embedding configuration and the vector search engine. Reports missing embedding configuration, a missing vector table, an unavailable native scan on shared storage, or mixed model spaces requiring the ordinary vector reader. Takes no arguments and changes no records.",
|
|
15
|
+
"input": {},
|
|
16
|
+
"readOnly": true
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
package/vocab.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// The vocabulary this package contributes, and nothing else
|
|
2
|
+
// (`@yaks/embedding/vocab`). It declares no component — no client ever writes
|
|
3
|
+
// a vector: it is derived from text another package's vocabulary declares, it
|
|
4
|
+
// is never sent to a client, and no patch creates one, which is why the table
|
|
5
|
+
// is created in SQL by ./graph.ts.
|
|
6
|
+
//
|
|
7
|
+
// What it does declare is one tool: the check in ./tools.ts. A tool is
|
|
8
|
+
// declared in a vocabulary and listed by the server, so the index's own
|
|
9
|
+
// invariant can be asked about the same way every other package's is.
|
|
10
|
+
import type { VocabDoc } from 'jsr:@yaks/vocab@0.2.36'
|
|
11
|
+
import doc from './vocab.json' with { type: 'json' }
|
|
12
|
+
import manifest from './package.json' with { type: 'json' }
|
|
13
|
+
|
|
14
|
+
/** The tool declaration this plugin contributes. */
|
|
15
|
+
export let embeddingDoc: VocabDoc = doc
|
|
16
|
+
|
|
17
|
+
/** What this package is: its manifest's description, the one place it is
|
|
18
|
+
* written, which a host stamps on each document here. */
|
|
19
|
+
export let description: string = manifest.description
|
|
20
|
+
|
|
21
|
+
/** Every document this plugin declares. */
|
|
22
|
+
export let docs: VocabDoc[] = [embeddingDoc]
|