@qvac/core 0.2.2 → 0.3.1
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/dist-lib/lib/api/agents.js +2 -3
- package/dist-lib/lib/api/chat.d.ts +3 -1
- package/dist-lib/lib/api/chat.js +9 -5
- package/dist-lib/lib/api/chunks.d.ts +1 -1
- package/dist-lib/lib/api/chunks.js +5 -15
- package/dist-lib/lib/api/current-mesh.d.ts +16 -1
- package/dist-lib/lib/api/current-mesh.js +18 -0
- package/dist-lib/lib/api/devices.js +6 -3
- package/dist-lib/lib/api/index.d.ts +2 -0
- package/dist-lib/lib/api/index.js +4 -2
- package/dist-lib/lib/api/inference-calls.d.ts +18 -0
- package/dist-lib/lib/api/inference-calls.js +15 -0
- package/dist-lib/lib/api/knowledge.js +11 -7
- package/dist-lib/lib/api/members.js +2 -3
- package/dist-lib/lib/api/rag.js +10 -2
- package/dist-lib/lib/api/sync.d.ts +1 -1
- package/dist-lib/lib/api/sync.js +2 -1
- package/dist-lib/lib/api/tool-activity.js +2 -2
- package/dist-lib/lib/api/tool-configs.js +2 -2
- package/dist-lib/lib/api/watchable.d.ts +6 -1
- package/dist-lib/lib/api/watchable.js +13 -2
- package/dist-lib/lib/assistant/harness.d.ts +1 -0
- package/dist-lib/lib/assistant/history.d.ts +1 -2
- package/dist-lib/lib/assistant/history.js +0 -6
- package/dist-lib/lib/assistant-tree.d.ts +2 -0
- package/dist-lib/lib/assistant-tree.js +11 -2
- package/dist-lib/lib/assistant.d.ts +17 -8
- package/dist-lib/lib/assistant.js +172 -125
- package/dist-lib/lib/core/chunk.d.ts +1 -0
- package/dist-lib/lib/core/chunk.js +32 -0
- package/dist-lib/lib/core/contract/devices.js +3 -2
- package/dist-lib/lib/core/files/rag/build.d.ts +1 -2
- package/dist-lib/lib/core/files/rag/build.js +1 -2
- package/dist-lib/lib/core/files/rag/extract/office-collabora.d.ts +1 -1
- package/dist-lib/lib/core/files/rag/index.d.ts +4 -24
- package/dist-lib/lib/core/files/rag/index.js +3 -17
- package/dist-lib/lib/core/files/rag/load.d.ts +1 -2
- package/dist-lib/lib/core/files/rag/load.js +1 -2
- package/dist-lib/lib/core/files/rag/produce.d.ts +1 -1
- package/dist-lib/lib/core/files/rag/produce.js +1 -3
- package/dist-lib/lib/core/files/rag/retrieval/full-text.d.ts +1 -1
- package/dist-lib/lib/core/files/rag/retrieval/full-text.js +1 -4
- package/dist-lib/lib/core/files/rag/similarity.d.ts +5 -0
- package/dist-lib/lib/core/files/rag/similarity.js +6 -0
- package/dist-lib/lib/core/files/upload.d.ts +1 -1
- package/dist-lib/lib/core/harness-loan.js +1 -1
- package/dist-lib/lib/core/inference-calls-handoff.d.ts +20 -0
- package/dist-lib/lib/core/inference-calls-handoff.js +37 -0
- package/dist-lib/lib/core/inference-calls-receiver.d.ts +14 -0
- package/dist-lib/lib/core/inference-calls-receiver.js +39 -0
- package/dist-lib/lib/core/local/index.js +6 -0
- package/dist-lib/lib/core/notification.js +5 -4
- package/dist-lib/lib/core.d.ts +9 -1
- package/dist-lib/lib/core.js +98 -16
- package/dist-lib/lib/fs-drive-bridge.js +1 -1
- package/dist-lib/lib/inference-calls.d.ts +40 -0
- package/dist-lib/lib/inference-calls.js +266 -0
- package/dist-lib/lib/mesh-scoped-engine.js +5 -0
- package/dist-lib/lib/model-download.d.ts +2 -0
- package/dist-lib/lib/model-download.js +20 -5
- package/dist-lib/lib/oauth/keys.js +1 -0
- package/dist-lib/lib/oauth/spotify.js +1 -0
- package/dist-lib/lib/oauth/verify.d.ts +8 -0
- package/dist-lib/lib/oauth/verify.js +58 -0
- package/dist-lib/lib/oauth.d.ts +1 -0
- package/dist-lib/lib/oauth.js +1 -0
- package/dist-lib/schema/content.js +5 -1
- package/dist-lib/schema/engine.js +42 -1
- package/dist-lib/schema/qvac.d.ts +3 -0
- package/dist-lib/schema/qvac.js +11 -2
- package/dist-lib/spec/bind.js +3 -0
- package/dist-lib/spec/calls.js +1 -0
- package/dist-lib/spec/capabilities.d.ts +2 -0
- package/dist-lib/spec/hrpc/hrpc.json +13 -0
- package/dist-lib/spec/hrpc/index.js +15 -3
- package/dist-lib/spec/hrpc/messages.js +172 -49
- package/dist-lib/spec/hyperschema/index.js +172 -49
- package/dist-lib/spec/hyperschema/schema.json +127 -1
- package/dist-lib/spec/hyperschema/types.d.ts +34 -1
- package/dist-lib/spec/local/hyperdb/messages.js +64 -128
- package/dist-lib/spec/local/hyperschema/index.js +32 -64
- package/dist-lib/spec/local/hyperschema/schema.json +16 -0
- package/dist-lib/spec/mesh/hyperdb/messages.js +176 -311
- package/dist-lib/spec/mesh/hyperdispatch/messages.js +132 -236
- package/dist-lib/spec/mesh/hyperschema/index.js +132 -236
- package/dist-lib/spec/mesh/hyperschema/schema.json +70 -1
- package/dist-lib/spec/mesh/hyperschema/types.d.ts +3 -1
- package/package.json +14 -17
- package/tui/app.mjs +327 -46
- package/tui/lib/knowledge-import.mjs +1 -1
- package/tui/lib/render.mjs +17 -1
- package/tui/lib/selection.mjs +16 -0
- package/tui/lib/usage.mjs +54 -0
- package/.claude/skills/asana/SKILL.md +0 -86
- package/.claude/skills/compaction/SKILL.md +0 -132
- package/.claude/skills/device-mesh-debug/SKILL.md +0 -328
- package/.claude/skills/gh-stack/SKILL.md +0 -181
- package/.claude/skills/gh-stack/references/commands.md +0 -177
- package/.claude/skills/gh-stack/references/stack-design.md +0 -97
- package/.claude/skills/gh-stack/references/troubleshooting.md +0 -159
- package/.claude/skills/js-house-style/SKILL.md +0 -670
- package/.claude/skills/pr-create/SKILL.md +0 -201
- package/.claude/skills/pr-review/SKILL.md +0 -424
- package/CLAUDE.md +0 -43
- package/dist-lib/lib/core/files/rag/artifact/codec.d.ts +0 -3
- package/dist-lib/lib/core/files/rag/artifact/codec.js +0 -172
- package/dist-lib/lib/core/files/rag/artifact/id.d.ts +0 -10
- package/dist-lib/lib/core/files/rag/artifact/id.js +0 -39
- package/dist-lib/lib/core/files/rag/artifact/types.d.ts +0 -24
- package/dist-lib/lib/core/files/rag/artifact/types.js +0 -41
- package/dist-lib/lib/core/files/rag/chunk/chunking.d.ts +0 -12
- package/dist-lib/lib/core/files/rag/chunk/chunking.js +0 -117
- package/dist-lib/lib/core/files/rag/chunk/metadata.d.ts +0 -30
- package/dist-lib/lib/core/files/rag/chunk/metadata.js +0 -89
- package/dist-lib/lib/core/files/rag/chunk/tokenizer.d.ts +0 -7
- package/dist-lib/lib/core/files/rag/chunk/tokenizer.js +0 -18
- package/dist-lib/lib/core/files/rag/extract/csv-text.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/extract/csv-text.js +0 -117
- package/dist-lib/lib/core/files/rag/extract/document-types.d.ts +0 -22
- package/dist-lib/lib/core/files/rag/extract/document-types.js +0 -152
- package/dist-lib/lib/core/files/rag/extract/extract.d.ts +0 -17
- package/dist-lib/lib/core/files/rag/extract/extract.js +0 -81
- package/dist-lib/lib/core/files/rag/extract/html-table-text.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/extract/html-table-text.js +0 -125
- package/dist-lib/lib/core/files/rag/extract/html-text.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/extract/html-text.js +0 -132
- package/dist-lib/lib/core/files/rag/extract/pdf-platform.d.ts +0 -17
- package/dist-lib/lib/core/files/rag/extract/pdf-platform.js +0 -141
- package/dist-lib/lib/core/files/rag/extract/pdf-text.d.ts +0 -12
- package/dist-lib/lib/core/files/rag/extract/pdf-text.js +0 -43
- package/dist-lib/lib/core/files/rag/extract/rtf-text.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/extract/rtf-text.js +0 -15
- package/dist-lib/lib/core/files/rag/extract/text-decoding.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/extract/text-decoding.js +0 -91
- package/dist-lib/lib/core/files/rag/extract/types.d.ts +0 -36
- package/dist-lib/lib/core/files/rag/extract/types.js +0 -12
- package/dist-lib/lib/core/files/rag/extract/utf.d.ts +0 -2
- package/dist-lib/lib/core/files/rag/extract/utf.js +0 -18
- package/dist-lib/lib/core/files/rag/retrieval/citation-match.d.ts +0 -2
- package/dist-lib/lib/core/files/rag/retrieval/citation-match.js +0 -16
- package/dist-lib/lib/core/files/rag/retrieval/coverage.d.ts +0 -4
- package/dist-lib/lib/core/files/rag/retrieval/coverage.js +0 -48
- package/dist-lib/lib/core/files/rag/retrieval/diversity.d.ts +0 -10
- package/dist-lib/lib/core/files/rag/retrieval/diversity.js +0 -37
- package/dist-lib/lib/core/files/rag/retrieval/floor.d.ts +0 -5
- package/dist-lib/lib/core/files/rag/retrieval/floor.js +0 -21
- package/dist-lib/lib/core/files/rag/retrieval/format.d.ts +0 -6
- package/dist-lib/lib/core/files/rag/retrieval/format.js +0 -21
- package/dist-lib/lib/core/files/rag/retrieval/knowledge.d.ts +0 -2
- package/dist-lib/lib/core/files/rag/retrieval/knowledge.js +0 -54
- package/dist-lib/lib/core/files/rag/retrieval/notices.d.ts +0 -16
- package/dist-lib/lib/core/files/rag/retrieval/notices.js +0 -27
- package/dist-lib/lib/core/files/rag/retrieval/scoring.d.ts +0 -8
- package/dist-lib/lib/core/files/rag/retrieval/scoring.js +0 -82
- package/dist-lib/lib/core/files/rag/retrieval/search.d.ts +0 -3
- package/dist-lib/lib/core/files/rag/retrieval/search.js +0 -49
- package/dist-lib/lib/core/files/rag/retrieval/selection.d.ts +0 -11
- package/dist-lib/lib/core/files/rag/retrieval/selection.js +0 -93
- package/dist-lib/lib/core/files/rag/retrieval/source-tag-filter.d.ts +0 -6
- package/dist-lib/lib/core/files/rag/retrieval/source-tag-filter.js +0 -79
- package/dist-lib/lib/core/files/rag/retrieval/sources.d.ts +0 -13
- package/dist-lib/lib/core/files/rag/retrieval/sources.js +0 -20
- package/dist-lib/lib/core/files/rag/retrieval/target.d.ts +0 -13
- package/dist-lib/lib/core/files/rag/retrieval/target.js +0 -89
- package/dist-lib/lib/core/files/rag/retrieval/terms.d.ts +0 -8
- package/dist-lib/lib/core/files/rag/retrieval/terms.js +0 -70
- package/dist-lib/lib/core/files/rag/retrieval/types.d.ts +0 -29
- package/dist-lib/lib/core/files/rag/retrieval/types.js +0 -1
- package/dist-lib/lib/core/files/rag/retrieval/web-sources.d.ts +0 -8
- package/dist-lib/lib/core/files/rag/retrieval/web-sources.js +0 -41
- package/dist-lib/lib/core/files/rag/retrieval/whole-document-query.d.ts +0 -1
- package/dist-lib/lib/core/files/rag/retrieval/whole-document-query.js +0 -96
- package/dist-lib/lib/core/files/rag/vector/memory.d.ts +0 -15
- package/dist-lib/lib/core/files/rag/vector/memory.js +0 -135
- package/dist-lib/lib/core/files/rag/vector/types.d.ts +0 -28
- package/dist-lib/lib/core/files/rag/vector/types.js +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isWholeDocumentQuery(query: string): boolean;
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
const SUMMARIZE_MARKERS = [
|
|
2
|
-
/\bsummar(?:ize|ise|y|ies)\b/,
|
|
3
|
-
/\btldr\b/,
|
|
4
|
-
/\boverview\b/,
|
|
5
|
-
/\bkey (?:points|takeaways)\b/,
|
|
6
|
-
/\bmain (?:points|ideas)\b/,
|
|
7
|
-
/\bgist\b/,
|
|
8
|
-
/\brecap\b/,
|
|
9
|
-
/\bwhat(?:'s| is| are)? (?:this|these|it) about\b/,
|
|
10
|
-
/\bwhat(?:'s| is| are) (?:in|on)\b/,
|
|
11
|
-
/\bwhat (?:do|does)\b.*\bcontain\b/
|
|
12
|
-
];
|
|
13
|
-
const FILLER = new Set([
|
|
14
|
-
'a',
|
|
15
|
-
'about',
|
|
16
|
-
'all',
|
|
17
|
-
'an',
|
|
18
|
-
'and',
|
|
19
|
-
'attached',
|
|
20
|
-
'brief',
|
|
21
|
-
'briefly',
|
|
22
|
-
'can',
|
|
23
|
-
'concise',
|
|
24
|
-
'content',
|
|
25
|
-
'contents',
|
|
26
|
-
'contain',
|
|
27
|
-
'do',
|
|
28
|
-
'does',
|
|
29
|
-
'doc',
|
|
30
|
-
'docs',
|
|
31
|
-
'document',
|
|
32
|
-
'documents',
|
|
33
|
-
'file',
|
|
34
|
-
'files',
|
|
35
|
-
'for',
|
|
36
|
-
'give',
|
|
37
|
-
'in',
|
|
38
|
-
'is',
|
|
39
|
-
'it',
|
|
40
|
-
'its',
|
|
41
|
-
'me',
|
|
42
|
-
'my',
|
|
43
|
-
'of',
|
|
44
|
-
'on',
|
|
45
|
-
'pdf',
|
|
46
|
-
'please',
|
|
47
|
-
'provide',
|
|
48
|
-
'short',
|
|
49
|
-
'some',
|
|
50
|
-
'the',
|
|
51
|
-
'their',
|
|
52
|
-
'them',
|
|
53
|
-
'these',
|
|
54
|
-
'this',
|
|
55
|
-
'those',
|
|
56
|
-
'to',
|
|
57
|
-
'up',
|
|
58
|
-
'us',
|
|
59
|
-
'what',
|
|
60
|
-
'whole',
|
|
61
|
-
'you',
|
|
62
|
-
'your'
|
|
63
|
-
]);
|
|
64
|
-
const MARKER_WORDS = new Set([
|
|
65
|
-
'are',
|
|
66
|
-
'dr',
|
|
67
|
-
'gist',
|
|
68
|
-
'ideas',
|
|
69
|
-
'key',
|
|
70
|
-
'main',
|
|
71
|
-
'overview',
|
|
72
|
-
'points',
|
|
73
|
-
'recap',
|
|
74
|
-
'summaries',
|
|
75
|
-
'summarise',
|
|
76
|
-
'summarize',
|
|
77
|
-
'summary',
|
|
78
|
-
'takeaways',
|
|
79
|
-
'tl',
|
|
80
|
-
'tldr'
|
|
81
|
-
]);
|
|
82
|
-
const CLAUSE_BOUNDARY = /[.!?;\n]+|\band\b|\balso\b|\bthen\b/;
|
|
83
|
-
export function isWholeDocumentQuery(query) {
|
|
84
|
-
const normalized = query
|
|
85
|
-
.toLowerCase()
|
|
86
|
-
.replace(/\bwhat's\b/g, 'what is')
|
|
87
|
-
.replace(/\btl[;:\s-]?dr\b/g, 'tldr')
|
|
88
|
-
.replace(/[_-]+/g, ' ');
|
|
89
|
-
return normalized.split(CLAUSE_BOUNDARY).some(isBareSummarizeClause);
|
|
90
|
-
}
|
|
91
|
-
function isBareSummarizeClause(clause) {
|
|
92
|
-
if (!SUMMARIZE_MARKERS.some((marker) => marker.test(clause)))
|
|
93
|
-
return false;
|
|
94
|
-
const words = clause.match(/[a-z0-9]+/g) ?? [];
|
|
95
|
-
return words.every((word) => FILLER.has(word) || MARKER_WORDS.has(word));
|
|
96
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { VectorCandidate, VectorChunk, VectorHit, VectorIndex, VectorIndexInfo } from './types.ts';
|
|
2
|
-
export declare class MemoryVectorIndex implements VectorIndex {
|
|
3
|
-
private readonly _artifacts;
|
|
4
|
-
private _chunks;
|
|
5
|
-
private _dimensions;
|
|
6
|
-
info(): VectorIndexInfo;
|
|
7
|
-
upsert(artifactId: string, chunks: ReadonlyArray<VectorChunk>): Promise<void>;
|
|
8
|
-
remove(artifactId: string): Promise<void>;
|
|
9
|
-
search(embedding: ReadonlyArray<number>, opts: {
|
|
10
|
-
readonly limit: number;
|
|
11
|
-
readonly filter?: (candidate: VectorCandidate) => boolean;
|
|
12
|
-
}): Promise<ReadonlyArray<VectorHit>>;
|
|
13
|
-
clear(): Promise<void>;
|
|
14
|
-
private _pack;
|
|
15
|
-
}
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
export class MemoryVectorIndex {
|
|
2
|
-
_artifacts = new Map();
|
|
3
|
-
_chunks = 0;
|
|
4
|
-
_dimensions = null;
|
|
5
|
-
info() {
|
|
6
|
-
return { artifacts: this._artifacts.size, chunks: this._chunks, dimensions: this._dimensions };
|
|
7
|
-
}
|
|
8
|
-
upsert(artifactId, chunks) {
|
|
9
|
-
const packed = this._pack(chunks);
|
|
10
|
-
const prev = this._artifacts.get(artifactId);
|
|
11
|
-
if (prev)
|
|
12
|
-
this._chunks -= prev.ids.length;
|
|
13
|
-
this._artifacts.set(artifactId, packed.artifact);
|
|
14
|
-
this._chunks += packed.artifact.ids.length;
|
|
15
|
-
if (packed.dimensions !== null && this._dimensions === null) {
|
|
16
|
-
this._dimensions = packed.dimensions;
|
|
17
|
-
}
|
|
18
|
-
if (this._chunks === 0)
|
|
19
|
-
this._dimensions = null;
|
|
20
|
-
return Promise.resolve();
|
|
21
|
-
}
|
|
22
|
-
remove(artifactId) {
|
|
23
|
-
const prev = this._artifacts.get(artifactId);
|
|
24
|
-
if (!prev)
|
|
25
|
-
return Promise.resolve();
|
|
26
|
-
this._artifacts.delete(artifactId);
|
|
27
|
-
this._chunks -= prev.ids.length;
|
|
28
|
-
if (this._chunks === 0)
|
|
29
|
-
this._dimensions = null;
|
|
30
|
-
return Promise.resolve();
|
|
31
|
-
}
|
|
32
|
-
search(embedding, opts) {
|
|
33
|
-
if (this._chunks === 0 || opts.limit <= 0)
|
|
34
|
-
return Promise.resolve([]);
|
|
35
|
-
if (this._dimensions !== null && embedding.length !== this._dimensions) {
|
|
36
|
-
throw new Error(`vector index: query has ${embedding.length} dimensions, the index holds ${this._dimensions}`);
|
|
37
|
-
}
|
|
38
|
-
const dimensions = embedding.length;
|
|
39
|
-
const query = new Float64Array(dimensions);
|
|
40
|
-
let sum = 0;
|
|
41
|
-
for (let d = 0; d < dimensions; d++) {
|
|
42
|
-
const value = embedding[d];
|
|
43
|
-
if (!Number.isFinite(value))
|
|
44
|
-
throw new Error('vector index: query embedding is not finite');
|
|
45
|
-
query[d] = value;
|
|
46
|
-
sum += value * value;
|
|
47
|
-
}
|
|
48
|
-
const queryNorm = Math.sqrt(sum);
|
|
49
|
-
const scored = [];
|
|
50
|
-
for (const artifact of this._artifacts.values()) {
|
|
51
|
-
for (let i = 0; i < artifact.ids.length; i++) {
|
|
52
|
-
if (opts.filter) {
|
|
53
|
-
const candidate = {
|
|
54
|
-
id: artifact.ids[i],
|
|
55
|
-
content: artifact.contents[i],
|
|
56
|
-
metadataJson: artifact.metadataJsons[i]
|
|
57
|
-
};
|
|
58
|
-
if (!opts.filter(candidate))
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
let dot = 0;
|
|
62
|
-
const base = i * dimensions;
|
|
63
|
-
for (let d = 0; d < dimensions; d++)
|
|
64
|
-
dot += artifact.vectors[base + d] * query[d];
|
|
65
|
-
const denominator = artifact.norms[i] * queryNorm;
|
|
66
|
-
scored.push({
|
|
67
|
-
id: artifact.ids[i],
|
|
68
|
-
content: artifact.contents[i],
|
|
69
|
-
metadataJson: artifact.metadataJsons[i],
|
|
70
|
-
cosine: denominator > 0 ? dot / denominator : 0
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
scored.sort((a, b) => b.cosine - a.cosine);
|
|
75
|
-
const results = scored.slice(0, opts.limit).map((entry) => ({
|
|
76
|
-
id: entry.id,
|
|
77
|
-
content: entry.content,
|
|
78
|
-
metadataJson: entry.metadataJson,
|
|
79
|
-
score: Math.max(0, entry.cosine)
|
|
80
|
-
}));
|
|
81
|
-
return Promise.resolve(results);
|
|
82
|
-
}
|
|
83
|
-
clear() {
|
|
84
|
-
this._artifacts.clear();
|
|
85
|
-
this._chunks = 0;
|
|
86
|
-
this._dimensions = null;
|
|
87
|
-
return Promise.resolve();
|
|
88
|
-
}
|
|
89
|
-
_pack(chunks) {
|
|
90
|
-
if (chunks.length === 0) {
|
|
91
|
-
return {
|
|
92
|
-
artifact: {
|
|
93
|
-
ids: [],
|
|
94
|
-
contents: [],
|
|
95
|
-
metadataJsons: [],
|
|
96
|
-
vectors: new Float32Array(0),
|
|
97
|
-
norms: new Float64Array(0)
|
|
98
|
-
},
|
|
99
|
-
dimensions: null
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
const dimensions = chunks[0].embedding.length;
|
|
103
|
-
if (dimensions === 0)
|
|
104
|
-
throw new Error('vector index: chunk embedding is empty');
|
|
105
|
-
if (this._dimensions !== null && dimensions !== this._dimensions) {
|
|
106
|
-
throw new Error(`vector index: artifact has ${dimensions} dimensions, the index holds ${this._dimensions}`);
|
|
107
|
-
}
|
|
108
|
-
const ids = [];
|
|
109
|
-
const contents = [];
|
|
110
|
-
const metadataJsons = [];
|
|
111
|
-
const vectors = new Float32Array(chunks.length * dimensions);
|
|
112
|
-
const norms = new Float64Array(chunks.length);
|
|
113
|
-
for (let i = 0; i < chunks.length; i++) {
|
|
114
|
-
const chunk = chunks[i];
|
|
115
|
-
if (chunk.embedding.length !== dimensions) {
|
|
116
|
-
throw new Error(`vector index: chunk ${chunk.id} disagrees on dimensions`);
|
|
117
|
-
}
|
|
118
|
-
let sum = 0;
|
|
119
|
-
for (let d = 0; d < dimensions; d++) {
|
|
120
|
-
const value = chunk.embedding[d];
|
|
121
|
-
if (!Number.isFinite(value)) {
|
|
122
|
-
throw new Error(`vector index: chunk ${chunk.id} embedding is not finite`);
|
|
123
|
-
}
|
|
124
|
-
const stored = Math.fround(value);
|
|
125
|
-
vectors[i * dimensions + d] = stored;
|
|
126
|
-
sum += stored * stored;
|
|
127
|
-
}
|
|
128
|
-
norms[i] = Math.sqrt(sum);
|
|
129
|
-
ids.push(chunk.id);
|
|
130
|
-
contents.push(chunk.content);
|
|
131
|
-
metadataJsons.push(chunk.metadataJson);
|
|
132
|
-
}
|
|
133
|
-
return { artifact: { ids, contents, metadataJsons, vectors, norms }, dimensions };
|
|
134
|
-
}
|
|
135
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export type VectorChunk = {
|
|
2
|
-
readonly id: string;
|
|
3
|
-
readonly content: string;
|
|
4
|
-
readonly metadataJson: string;
|
|
5
|
-
readonly embedding: ReadonlyArray<number>;
|
|
6
|
-
};
|
|
7
|
-
export type VectorHit = {
|
|
8
|
-
readonly id: string;
|
|
9
|
-
readonly content: string;
|
|
10
|
-
readonly metadataJson: string;
|
|
11
|
-
readonly score: number;
|
|
12
|
-
};
|
|
13
|
-
export type VectorCandidate = Omit<VectorHit, 'score'>;
|
|
14
|
-
export type VectorIndexInfo = {
|
|
15
|
-
readonly artifacts: number;
|
|
16
|
-
readonly chunks: number;
|
|
17
|
-
readonly dimensions: number | null;
|
|
18
|
-
};
|
|
19
|
-
export interface VectorIndex {
|
|
20
|
-
info(): VectorIndexInfo;
|
|
21
|
-
upsert(artifactId: string, chunks: ReadonlyArray<VectorChunk>): Promise<void>;
|
|
22
|
-
remove(artifactId: string): Promise<void>;
|
|
23
|
-
search(embedding: ReadonlyArray<number>, opts: {
|
|
24
|
-
readonly limit: number;
|
|
25
|
-
readonly filter?: (candidate: VectorCandidate) => boolean;
|
|
26
|
-
}): Promise<ReadonlyArray<VectorHit>>;
|
|
27
|
-
clear(): Promise<void>;
|
|
28
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|