@nodetool-ai/base-nodes 0.7.0-rc.23 → 0.8.2
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/README.md +21 -0
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/builtin-packs.d.ts +17 -0
- package/dist/builtin-packs.d.ts.map +1 -0
- package/dist/builtin-packs.js +95 -0
- package/dist/builtin-packs.js.map +1 -0
- package/dist/index.d.ts +63 -67
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +186 -173
- package/dist/index.js.map +1 -1
- package/dist/platforms/browser.d.ts +19 -0
- package/dist/platforms/browser.d.ts.map +1 -0
- package/dist/platforms/browser.js +29 -0
- package/dist/platforms/browser.js.map +1 -0
- package/package.json +72 -65
- package/dist/lib/audio-wav.d.ts +0 -66
- package/dist/lib/audio-wav.d.ts.map +0 -1
- package/dist/lib/audio-wav.js +0 -215
- package/dist/lib/audio-wav.js.map +0 -1
- package/dist/nodes/agent-tool-hydration.d.ts +0 -10
- package/dist/nodes/agent-tool-hydration.d.ts.map +0 -1
- package/dist/nodes/agent-tool-hydration.js +0 -43
- package/dist/nodes/agent-tool-hydration.js.map +0 -1
- package/dist/nodes/agents.d.ts +0 -262
- package/dist/nodes/agents.d.ts.map +0 -1
- package/dist/nodes/agents.js +0 -2856
- package/dist/nodes/agents.js.map +0 -1
- package/dist/nodes/anthropic.d.ts +0 -26
- package/dist/nodes/anthropic.d.ts.map +0 -1
- package/dist/nodes/anthropic.js +0 -133
- package/dist/nodes/anthropic.js.map +0 -1
- package/dist/nodes/apify.d.ts +0 -120
- package/dist/nodes/apify.d.ts.map +0 -1
- package/dist/nodes/apify.js +0 -618
- package/dist/nodes/apify.js.map +0 -1
- package/dist/nodes/audio.d.ts +0 -301
- package/dist/nodes/audio.d.ts.map +0 -1
- package/dist/nodes/audio.js +0 -1274
- package/dist/nodes/audio.js.map +0 -1
- package/dist/nodes/code-node.d.ts +0 -34
- package/dist/nodes/code-node.d.ts.map +0 -1
- package/dist/nodes/code-node.js +0 -343
- package/dist/nodes/code-node.js.map +0 -1
- package/dist/nodes/code.d.ts +0 -301
- package/dist/nodes/code.d.ts.map +0 -1
- package/dist/nodes/code.js +0 -850
- package/dist/nodes/code.js.map +0 -1
- package/dist/nodes/compare.d.ts +0 -18
- package/dist/nodes/compare.d.ts.map +0 -1
- package/dist/nodes/compare.js +0 -122
- package/dist/nodes/compare.js.map +0 -1
- package/dist/nodes/constant.d.ts +0 -315
- package/dist/nodes/constant.d.ts.map +0 -1
- package/dist/nodes/constant.js +0 -715
- package/dist/nodes/constant.js.map +0 -1
- package/dist/nodes/control.d.ts +0 -83
- package/dist/nodes/control.d.ts.map +0 -1
- package/dist/nodes/control.js +0 -212
- package/dist/nodes/control.js.map +0 -1
- package/dist/nodes/data.d.ts +0 -369
- package/dist/nodes/data.d.ts.map +0 -1
- package/dist/nodes/data.js +0 -1590
- package/dist/nodes/data.js.map +0 -1
- package/dist/nodes/document.d.ts +0 -134
- package/dist/nodes/document.d.ts.map +0 -1
- package/dist/nodes/document.js +0 -984
- package/dist/nodes/document.js.map +0 -1
- package/dist/nodes/extended-placeholders.d.ts +0 -6
- package/dist/nodes/extended-placeholders.d.ts.map +0 -1
- package/dist/nodes/extended-placeholders.js +0 -19
- package/dist/nodes/extended-placeholders.js.map +0 -1
- package/dist/nodes/gemini.d.ts +0 -110
- package/dist/nodes/gemini.d.ts.map +0 -1
- package/dist/nodes/gemini.js +0 -871
- package/dist/nodes/gemini.js.map +0 -1
- package/dist/nodes/generators.d.ts +0 -84
- package/dist/nodes/generators.d.ts.map +0 -1
- package/dist/nodes/generators.js +0 -968
- package/dist/nodes/generators.js.map +0 -1
- package/dist/nodes/image.d.ts +0 -232
- package/dist/nodes/image.d.ts.map +0 -1
- package/dist/nodes/image.js +0 -1395
- package/dist/nodes/image.js.map +0 -1
- package/dist/nodes/input.d.ts +0 -445
- package/dist/nodes/input.d.ts.map +0 -1
- package/dist/nodes/input.js +0 -1459
- package/dist/nodes/input.js.map +0 -1
- package/dist/nodes/kie-dynamic.d.ts +0 -31
- package/dist/nodes/kie-dynamic.d.ts.map +0 -1
- package/dist/nodes/kie-dynamic.js +0 -270
- package/dist/nodes/kie-dynamic.js.map +0 -1
- package/dist/nodes/lib-audio-dsp.d.ts +0 -85
- package/dist/nodes/lib-audio-dsp.d.ts.map +0 -1
- package/dist/nodes/lib-audio-dsp.js +0 -450
- package/dist/nodes/lib-audio-dsp.js.map +0 -1
- package/dist/nodes/lib-audio-effects.d.ts +0 -116
- package/dist/nodes/lib-audio-effects.d.ts.map +0 -1
- package/dist/nodes/lib-audio-effects.js +0 -905
- package/dist/nodes/lib-audio-effects.js.map +0 -1
- package/dist/nodes/lib-browser.d.ts +0 -99
- package/dist/nodes/lib-browser.d.ts.map +0 -1
- package/dist/nodes/lib-browser.js +0 -692
- package/dist/nodes/lib-browser.js.map +0 -1
- package/dist/nodes/lib-charts.d.ts +0 -20
- package/dist/nodes/lib-charts.d.ts.map +0 -1
- package/dist/nodes/lib-charts.js +0 -245
- package/dist/nodes/lib-charts.js.map +0 -1
- package/dist/nodes/lib-datetime.d.ts +0 -108
- package/dist/nodes/lib-datetime.d.ts.map +0 -1
- package/dist/nodes/lib-datetime.js +0 -421
- package/dist/nodes/lib-datetime.js.map +0 -1
- package/dist/nodes/lib-doc-convert.d.ts +0 -19
- package/dist/nodes/lib-doc-convert.d.ts.map +0 -1
- package/dist/nodes/lib-doc-convert.js +0 -257
- package/dist/nodes/lib-doc-convert.js.map +0 -1
- package/dist/nodes/lib-doc-transform.d.ts +0 -39
- package/dist/nodes/lib-doc-transform.d.ts.map +0 -1
- package/dist/nodes/lib-doc-transform.js +0 -335
- package/dist/nodes/lib-doc-transform.js.map +0 -1
- package/dist/nodes/lib-docx.d.ts +0 -106
- package/dist/nodes/lib-docx.d.ts.map +0 -1
- package/dist/nodes/lib-docx.js +0 -595
- package/dist/nodes/lib-docx.js.map +0 -1
- package/dist/nodes/lib-epub.d.ts +0 -55
- package/dist/nodes/lib-epub.d.ts.map +0 -1
- package/dist/nodes/lib-epub.js +0 -220
- package/dist/nodes/lib-epub.js.map +0 -1
- package/dist/nodes/lib-excel.d.ts +0 -74
- package/dist/nodes/lib-excel.d.ts.map +0 -1
- package/dist/nodes/lib-excel.js +0 -448
- package/dist/nodes/lib-excel.js.map +0 -1
- package/dist/nodes/lib-graphql.d.ts +0 -66
- package/dist/nodes/lib-graphql.d.ts.map +0 -1
- package/dist/nodes/lib-graphql.js +0 -333
- package/dist/nodes/lib-graphql.js.map +0 -1
- package/dist/nodes/lib-grid.d.ts +0 -27
- package/dist/nodes/lib-grid.d.ts.map +0 -1
- package/dist/nodes/lib-grid.js +0 -172
- package/dist/nodes/lib-grid.js.map +0 -1
- package/dist/nodes/lib-html-parse.d.ts +0 -108
- package/dist/nodes/lib-html-parse.d.ts.map +0 -1
- package/dist/nodes/lib-html-parse.js +0 -365
- package/dist/nodes/lib-html-parse.js.map +0 -1
- package/dist/nodes/lib-http.d.ts +0 -98
- package/dist/nodes/lib-http.d.ts.map +0 -1
- package/dist/nodes/lib-http.js +0 -267
- package/dist/nodes/lib-http.js.map +0 -1
- package/dist/nodes/lib-image-color-grading.d.ts +0 -3
- package/dist/nodes/lib-image-color-grading.d.ts.map +0 -1
- package/dist/nodes/lib-image-color-grading.js +0 -1386
- package/dist/nodes/lib-image-color-grading.js.map +0 -1
- package/dist/nodes/lib-image-draw.d.ts +0 -3
- package/dist/nodes/lib-image-draw.d.ts.map +0 -1
- package/dist/nodes/lib-image-draw.js +0 -470
- package/dist/nodes/lib-image-draw.js.map +0 -1
- package/dist/nodes/lib-image-enhance.d.ts +0 -3
- package/dist/nodes/lib-image-enhance.d.ts.map +0 -1
- package/dist/nodes/lib-image-enhance.js +0 -731
- package/dist/nodes/lib-image-enhance.js.map +0 -1
- package/dist/nodes/lib-image-filter.d.ts +0 -3
- package/dist/nodes/lib-image-filter.d.ts.map +0 -1
- package/dist/nodes/lib-image-filter.js +0 -684
- package/dist/nodes/lib-image-filter.js.map +0 -1
- package/dist/nodes/lib-image-utils.d.ts +0 -24
- package/dist/nodes/lib-image-utils.d.ts.map +0 -1
- package/dist/nodes/lib-image-utils.js +0 -150
- package/dist/nodes/lib-image-utils.js.map +0 -1
- package/dist/nodes/lib-mail.d.ts +0 -74
- package/dist/nodes/lib-mail.d.ts.map +0 -1
- package/dist/nodes/lib-mail.js +0 -452
- package/dist/nodes/lib-mail.js.map +0 -1
- package/dist/nodes/lib-markdown.d.ts +0 -70
- package/dist/nodes/lib-markdown.d.ts.map +0 -1
- package/dist/nodes/lib-markdown.js +0 -236
- package/dist/nodes/lib-markdown.js.map +0 -1
- package/dist/nodes/lib-nlp.d.ts +0 -98
- package/dist/nodes/lib-nlp.d.ts.map +0 -1
- package/dist/nodes/lib-nlp.js +0 -374
- package/dist/nodes/lib-nlp.js.map +0 -1
- package/dist/nodes/lib-notion.d.ts +0 -99
- package/dist/nodes/lib-notion.d.ts.map +0 -1
- package/dist/nodes/lib-notion.js +0 -601
- package/dist/nodes/lib-notion.js.map +0 -1
- package/dist/nodes/lib-ocr.d.ts +0 -31
- package/dist/nodes/lib-ocr.d.ts.map +0 -1
- package/dist/nodes/lib-ocr.js +0 -143
- package/dist/nodes/lib-ocr.js.map +0 -1
- package/dist/nodes/lib-os.d.ts +0 -312
- package/dist/nodes/lib-os.d.ts.map +0 -1
- package/dist/nodes/lib-os.js +0 -909
- package/dist/nodes/lib-os.js.map +0 -1
- package/dist/nodes/lib-pdf.d.ts +0 -142
- package/dist/nodes/lib-pdf.d.ts.map +0 -1
- package/dist/nodes/lib-pdf.js +0 -871
- package/dist/nodes/lib-pdf.js.map +0 -1
- package/dist/nodes/lib-pptx.d.ts +0 -29
- package/dist/nodes/lib-pptx.d.ts.map +0 -1
- package/dist/nodes/lib-pptx.js +0 -122
- package/dist/nodes/lib-pptx.js.map +0 -1
- package/dist/nodes/lib-rss.d.ts +0 -31
- package/dist/nodes/lib-rss.d.ts.map +0 -1
- package/dist/nodes/lib-rss.js +0 -163
- package/dist/nodes/lib-rss.js.map +0 -1
- package/dist/nodes/lib-s3.d.ts +0 -112
- package/dist/nodes/lib-s3.d.ts.map +0 -1
- package/dist/nodes/lib-s3.js +0 -521
- package/dist/nodes/lib-s3.js.map +0 -1
- package/dist/nodes/lib-secret.d.ts +0 -15
- package/dist/nodes/lib-secret.d.ts.map +0 -1
- package/dist/nodes/lib-secret.js +0 -42
- package/dist/nodes/lib-secret.js.map +0 -1
- package/dist/nodes/lib-sqlite.d.ts +0 -102
- package/dist/nodes/lib-sqlite.d.ts.map +0 -1
- package/dist/nodes/lib-sqlite.js +0 -532
- package/dist/nodes/lib-sqlite.js.map +0 -1
- package/dist/nodes/lib-supabase.d.ts +0 -86
- package/dist/nodes/lib-supabase.d.ts.map +0 -1
- package/dist/nodes/lib-supabase.js +0 -425
- package/dist/nodes/lib-supabase.js.map +0 -1
- package/dist/nodes/lib-svg.d.ts +0 -199
- package/dist/nodes/lib-svg.d.ts.map +0 -1
- package/dist/nodes/lib-svg.js +0 -1027
- package/dist/nodes/lib-svg.js.map +0 -1
- package/dist/nodes/lib-tensorflow.d.ts +0 -71
- package/dist/nodes/lib-tensorflow.d.ts.map +0 -1
- package/dist/nodes/lib-tensorflow.js +0 -351
- package/dist/nodes/lib-tensorflow.js.map +0 -1
- package/dist/nodes/lib-twilio.d.ts +0 -71
- package/dist/nodes/lib-twilio.d.ts.map +0 -1
- package/dist/nodes/lib-twilio.js +0 -469
- package/dist/nodes/lib-twilio.js.map +0 -1
- package/dist/nodes/lib-validate.d.ts +0 -84
- package/dist/nodes/lib-validate.d.ts.map +0 -1
- package/dist/nodes/lib-validate.js +0 -215
- package/dist/nodes/lib-validate.js.map +0 -1
- package/dist/nodes/lib-video-download.d.ts +0 -26
- package/dist/nodes/lib-video-download.d.ts.map +0 -1
- package/dist/nodes/lib-video-download.js +0 -299
- package/dist/nodes/lib-video-download.js.map +0 -1
- package/dist/nodes/messaging.d.ts +0 -88
- package/dist/nodes/messaging.d.ts.map +0 -1
- package/dist/nodes/messaging.js +0 -418
- package/dist/nodes/messaging.js.map +0 -1
- package/dist/nodes/mistral.d.ts +0 -83
- package/dist/nodes/mistral.d.ts.map +0 -1
- package/dist/nodes/mistral.js +0 -450
- package/dist/nodes/mistral.js.map +0 -1
- package/dist/nodes/model3d/analysis.d.ts +0 -13
- package/dist/nodes/model3d/analysis.d.ts.map +0 -1
- package/dist/nodes/model3d/analysis.js +0 -36
- package/dist/nodes/model3d/analysis.js.map +0 -1
- package/dist/nodes/model3d/base.d.ts +0 -11
- package/dist/nodes/model3d/base.d.ts.map +0 -1
- package/dist/nodes/model3d/base.js +0 -20
- package/dist/nodes/model3d/base.js.map +0 -1
- package/dist/nodes/model3d/boolean-ops.d.ts +0 -2
- package/dist/nodes/model3d/boolean-ops.d.ts.map +0 -1
- package/dist/nodes/model3d/boolean-ops.js +0 -172
- package/dist/nodes/model3d/boolean-ops.js.map +0 -1
- package/dist/nodes/model3d/cleanup.d.ts +0 -47
- package/dist/nodes/model3d/cleanup.d.ts.map +0 -1
- package/dist/nodes/model3d/cleanup.js +0 -136
- package/dist/nodes/model3d/cleanup.js.map +0 -1
- package/dist/nodes/model3d/convert.d.ts +0 -14
- package/dist/nodes/model3d/convert.d.ts.map +0 -1
- package/dist/nodes/model3d/convert.js +0 -64
- package/dist/nodes/model3d/convert.js.map +0 -1
- package/dist/nodes/model3d/defaults.d.ts +0 -34
- package/dist/nodes/model3d/defaults.d.ts.map +0 -1
- package/dist/nodes/model3d/defaults.js +0 -28
- package/dist/nodes/model3d/defaults.js.map +0 -1
- package/dist/nodes/model3d/document-ops.d.ts +0 -4
- package/dist/nodes/model3d/document-ops.d.ts.map +0 -1
- package/dist/nodes/model3d/document-ops.js +0 -40
- package/dist/nodes/model3d/document-ops.js.map +0 -1
- package/dist/nodes/model3d/generation.d.ts +0 -39
- package/dist/nodes/model3d/generation.d.ts.map +0 -1
- package/dist/nodes/model3d/generation.js +0 -179
- package/dist/nodes/model3d/generation.js.map +0 -1
- package/dist/nodes/model3d/glb.d.ts +0 -29
- package/dist/nodes/model3d/glb.d.ts.map +0 -1
- package/dist/nodes/model3d/glb.js +0 -255
- package/dist/nodes/model3d/glb.js.map +0 -1
- package/dist/nodes/model3d/index.d.ts +0 -20
- package/dist/nodes/model3d/index.d.ts.map +0 -1
- package/dist/nodes/model3d/index.js +0 -38
- package/dist/nodes/model3d/index.js.map +0 -1
- package/dist/nodes/model3d/io.d.ts +0 -38
- package/dist/nodes/model3d/io.d.ts.map +0 -1
- package/dist/nodes/model3d/io.js +0 -162
- package/dist/nodes/model3d/io.js.map +0 -1
- package/dist/nodes/model3d/mesh-ops.d.ts +0 -40
- package/dist/nodes/model3d/mesh-ops.d.ts.map +0 -1
- package/dist/nodes/model3d/mesh-ops.js +0 -775
- package/dist/nodes/model3d/mesh-ops.js.map +0 -1
- package/dist/nodes/model3d/nodes.d.ts +0 -2
- package/dist/nodes/model3d/nodes.d.ts.map +0 -1
- package/dist/nodes/model3d/nodes.js +0 -2
- package/dist/nodes/model3d/nodes.js.map +0 -1
- package/dist/nodes/model3d/ops.d.ts +0 -37
- package/dist/nodes/model3d/ops.d.ts.map +0 -1
- package/dist/nodes/model3d/ops.js +0 -137
- package/dist/nodes/model3d/ops.js.map +0 -1
- package/dist/nodes/model3d/transforms.d.ts +0 -49
- package/dist/nodes/model3d/transforms.d.ts.map +0 -1
- package/dist/nodes/model3d/transforms.js +0 -142
- package/dist/nodes/model3d/transforms.js.map +0 -1
- package/dist/nodes/model3d/types.d.ts +0 -81
- package/dist/nodes/model3d/types.d.ts.map +0 -1
- package/dist/nodes/model3d/types.js +0 -2
- package/dist/nodes/model3d/types.js.map +0 -1
- package/dist/nodes/model3d/utils.d.ts +0 -34
- package/dist/nodes/model3d/utils.d.ts.map +0 -1
- package/dist/nodes/model3d/utils.js +0 -185
- package/dist/nodes/model3d/utils.js.map +0 -1
- package/dist/nodes/model3d.d.ts +0 -2
- package/dist/nodes/model3d.d.ts.map +0 -1
- package/dist/nodes/model3d.js +0 -2
- package/dist/nodes/model3d.js.map +0 -1
- package/dist/nodes/openai.d.ts +0 -172
- package/dist/nodes/openai.d.ts.map +0 -1
- package/dist/nodes/openai.js +0 -1294
- package/dist/nodes/openai.js.map +0 -1
- package/dist/nodes/output.d.ts +0 -29
- package/dist/nodes/output.d.ts.map +0 -1
- package/dist/nodes/output.js +0 -87
- package/dist/nodes/output.js.map +0 -1
- package/dist/nodes/sandbox.d.ts +0 -63
- package/dist/nodes/sandbox.d.ts.map +0 -1
- package/dist/nodes/sandbox.js +0 -633
- package/dist/nodes/sandbox.js.map +0 -1
- package/dist/nodes/search.d.ts +0 -117
- package/dist/nodes/search.d.ts.map +0 -1
- package/dist/nodes/search.js +0 -607
- package/dist/nodes/search.js.map +0 -1
- package/dist/nodes/team.d.ts +0 -74
- package/dist/nodes/team.d.ts.map +0 -1
- package/dist/nodes/team.js +0 -309
- package/dist/nodes/team.js.map +0 -1
- package/dist/nodes/text-extra.d.ts +0 -633
- package/dist/nodes/text-extra.d.ts.map +0 -1
- package/dist/nodes/text-extra.js +0 -2226
- package/dist/nodes/text-extra.js.map +0 -1
- package/dist/nodes/tool-agents.d.ts +0 -334
- package/dist/nodes/tool-agents.d.ts.map +0 -1
- package/dist/nodes/tool-agents.js +0 -1861
- package/dist/nodes/tool-agents.js.map +0 -1
- package/dist/nodes/triggers.d.ts +0 -107
- package/dist/nodes/triggers.d.ts.map +0 -1
- package/dist/nodes/triggers.js +0 -706
- package/dist/nodes/triggers.js.map +0 -1
- package/dist/nodes/vector.d.ts +0 -168
- package/dist/nodes/vector.d.ts.map +0 -1
- package/dist/nodes/vector.js +0 -1121
- package/dist/nodes/vector.js.map +0 -1
- package/dist/nodes/video.d.ts +0 -387
- package/dist/nodes/video.d.ts.map +0 -1
- package/dist/nodes/video.js +0 -2383
- package/dist/nodes/video.js.map +0 -1
- package/dist/nodes/workflow.d.ts +0 -24
- package/dist/nodes/workflow.d.ts.map +0 -1
- package/dist/nodes/workflow.js +0 -146
- package/dist/nodes/workflow.js.map +0 -1
- package/dist/nodes/workspace.d.ts +0 -203
- package/dist/nodes/workspace.d.ts.map +0 -1
- package/dist/nodes/workspace.js +0 -795
- package/dist/nodes/workspace.js.map +0 -1
package/dist/nodes/vector.js
DELETED
|
@@ -1,1121 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Vector database nodes for NodeTool (sqlite-vec backed).
|
|
3
|
-
* Provides collection management, indexing, and querying operations.
|
|
4
|
-
*/
|
|
5
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
6
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
7
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
8
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
9
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
10
|
-
};
|
|
11
|
-
import { BaseNode, prop } from "@nodetool-ai/node-sdk";
|
|
12
|
-
import { getVecStore, getCollection, OllamaEmbeddingFunction } from "@nodetool-ai/vectorstore";
|
|
13
|
-
// ---------------------------------------------------------------------------
|
|
14
|
-
// Client helpers
|
|
15
|
-
// ---------------------------------------------------------------------------
|
|
16
|
-
async function getOllamaEmbedding(model, text) {
|
|
17
|
-
const ef = new OllamaEmbeddingFunction(model);
|
|
18
|
-
const result = await ef.generate([text]);
|
|
19
|
-
return result[0];
|
|
20
|
-
}
|
|
21
|
-
// ---------------------------------------------------------------------------
|
|
22
|
-
// 1. CollectionNode
|
|
23
|
-
// ---------------------------------------------------------------------------
|
|
24
|
-
export class CollectionNode extends BaseNode {
|
|
25
|
-
static nodeType = "vector.Collection";
|
|
26
|
-
static title = "Collection";
|
|
27
|
-
static description = "Get or create a named vector database collection for storing embeddings.\n vector, embedding, collection, RAG, get, create";
|
|
28
|
-
static metadataOutputTypes = {
|
|
29
|
-
output: "collection"
|
|
30
|
-
};
|
|
31
|
-
async process() {
|
|
32
|
-
const name = String(this.name ?? this.name ?? "");
|
|
33
|
-
const embeddingModel = (this.embedding_model ??
|
|
34
|
-
this.embedding_model ?? { repo_id: "" });
|
|
35
|
-
if (!name.trim()) {
|
|
36
|
-
throw new Error("Collection name cannot be empty");
|
|
37
|
-
}
|
|
38
|
-
const store = await getVecStore();
|
|
39
|
-
await store.getOrCreateCollection({
|
|
40
|
-
name,
|
|
41
|
-
metadata: { embedding_model: embeddingModel.repo_id ?? "" }
|
|
42
|
-
});
|
|
43
|
-
return { output: { name } };
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
__decorate([
|
|
47
|
-
prop({
|
|
48
|
-
type: "str",
|
|
49
|
-
default: "",
|
|
50
|
-
title: "Name",
|
|
51
|
-
description: "The name of the collection to create"
|
|
52
|
-
})
|
|
53
|
-
], CollectionNode.prototype, "name", void 0);
|
|
54
|
-
__decorate([
|
|
55
|
-
prop({
|
|
56
|
-
type: "llama_model",
|
|
57
|
-
default: {
|
|
58
|
-
type: "llama_model",
|
|
59
|
-
name: "",
|
|
60
|
-
repo_id: "",
|
|
61
|
-
modified_at: "",
|
|
62
|
-
size: 0,
|
|
63
|
-
digest: "",
|
|
64
|
-
details: {}
|
|
65
|
-
},
|
|
66
|
-
title: "Embedding Model",
|
|
67
|
-
description: "Model to use for embedding, search for nomic-embed-text and download it"
|
|
68
|
-
})
|
|
69
|
-
], CollectionNode.prototype, "embedding_model", void 0);
|
|
70
|
-
// ---------------------------------------------------------------------------
|
|
71
|
-
// 2. CountNode
|
|
72
|
-
// ---------------------------------------------------------------------------
|
|
73
|
-
export class CountNode extends BaseNode {
|
|
74
|
-
static nodeType = "vector.Count";
|
|
75
|
-
static title = "Count";
|
|
76
|
-
static description = "Count the number of documents in a collection.\n vector, embedding, collection, RAG";
|
|
77
|
-
static metadataOutputTypes = {
|
|
78
|
-
output: "int"
|
|
79
|
-
};
|
|
80
|
-
async process() {
|
|
81
|
-
const collectionInput = (this.collection ??
|
|
82
|
-
this.collection ?? { name: "" });
|
|
83
|
-
const name = collectionInput.name ?? "";
|
|
84
|
-
if (!name.trim())
|
|
85
|
-
throw new Error("Collection name cannot be empty");
|
|
86
|
-
const collection = await getCollection(name);
|
|
87
|
-
const count = await collection.count();
|
|
88
|
-
return { output: count };
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
__decorate([
|
|
92
|
-
prop({
|
|
93
|
-
type: "collection",
|
|
94
|
-
default: {
|
|
95
|
-
type: "collection",
|
|
96
|
-
name: ""
|
|
97
|
-
},
|
|
98
|
-
title: "Collection",
|
|
99
|
-
description: "The collection to count"
|
|
100
|
-
})
|
|
101
|
-
], CountNode.prototype, "collection", void 0);
|
|
102
|
-
// ---------------------------------------------------------------------------
|
|
103
|
-
// 3. GetDocumentsNode
|
|
104
|
-
// ---------------------------------------------------------------------------
|
|
105
|
-
export class GetDocumentsNode extends BaseNode {
|
|
106
|
-
static nodeType = "vector.GetDocuments";
|
|
107
|
-
static title = "Get Documents";
|
|
108
|
-
static description = "Get documents from a collection.\n vector, embedding, collection, RAG, retrieve";
|
|
109
|
-
static metadataOutputTypes = {
|
|
110
|
-
output: "list[str]"
|
|
111
|
-
};
|
|
112
|
-
async process() {
|
|
113
|
-
const collectionInput = (this.collection ??
|
|
114
|
-
this.collection ?? { name: "" });
|
|
115
|
-
const name = collectionInput.name ?? "";
|
|
116
|
-
if (!name.trim())
|
|
117
|
-
throw new Error("Collection name cannot be empty");
|
|
118
|
-
const ids = (this.ids ?? this.ids ?? []);
|
|
119
|
-
const limit = Number(this.limit ?? this.limit ?? 100);
|
|
120
|
-
const offset = Number(this.offset ?? this.offset ?? 0);
|
|
121
|
-
const collection = await getCollection(name);
|
|
122
|
-
// When ids is empty, pass empty array (returns nothing) to match Python behavior.
|
|
123
|
-
// Passing undefined would return all docs, which differs from Python's empty-list semantics.
|
|
124
|
-
const result = await collection.get({
|
|
125
|
-
ids: ids.length > 0 ? ids : [],
|
|
126
|
-
limit,
|
|
127
|
-
offset
|
|
128
|
-
});
|
|
129
|
-
return { output: result.documents };
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
__decorate([
|
|
133
|
-
prop({
|
|
134
|
-
type: "collection",
|
|
135
|
-
default: {
|
|
136
|
-
type: "collection",
|
|
137
|
-
name: ""
|
|
138
|
-
},
|
|
139
|
-
title: "Collection",
|
|
140
|
-
description: "The collection to get"
|
|
141
|
-
})
|
|
142
|
-
], GetDocumentsNode.prototype, "collection", void 0);
|
|
143
|
-
__decorate([
|
|
144
|
-
prop({
|
|
145
|
-
type: "list[str]",
|
|
146
|
-
default: [],
|
|
147
|
-
title: "Ids",
|
|
148
|
-
description: "The ids of the documents to get"
|
|
149
|
-
})
|
|
150
|
-
], GetDocumentsNode.prototype, "ids", void 0);
|
|
151
|
-
__decorate([
|
|
152
|
-
prop({
|
|
153
|
-
type: "int",
|
|
154
|
-
default: 100,
|
|
155
|
-
title: "Limit",
|
|
156
|
-
description: "The limit of the documents to get"
|
|
157
|
-
})
|
|
158
|
-
], GetDocumentsNode.prototype, "limit", void 0);
|
|
159
|
-
__decorate([
|
|
160
|
-
prop({
|
|
161
|
-
type: "int",
|
|
162
|
-
default: 0,
|
|
163
|
-
title: "Offset",
|
|
164
|
-
description: "The offset of the documents to get"
|
|
165
|
-
})
|
|
166
|
-
], GetDocumentsNode.prototype, "offset", void 0);
|
|
167
|
-
// ---------------------------------------------------------------------------
|
|
168
|
-
// 4. PeekNode
|
|
169
|
-
// ---------------------------------------------------------------------------
|
|
170
|
-
export class PeekNode extends BaseNode {
|
|
171
|
-
static nodeType = "vector.Peek";
|
|
172
|
-
static title = "Peek";
|
|
173
|
-
static description = "Peek at the documents in a collection.\n vector, embedding, collection, RAG, preview";
|
|
174
|
-
static metadataOutputTypes = {
|
|
175
|
-
output: "list[str]"
|
|
176
|
-
};
|
|
177
|
-
async process() {
|
|
178
|
-
const collectionInput = (this.collection ??
|
|
179
|
-
this.collection ?? { name: "" });
|
|
180
|
-
const name = collectionInput.name ?? "";
|
|
181
|
-
if (!name.trim())
|
|
182
|
-
throw new Error("Collection name cannot be empty");
|
|
183
|
-
const limit = Number(this.limit ?? this.limit ?? 100);
|
|
184
|
-
const collection = await getCollection(name);
|
|
185
|
-
const result = await collection.peek({ limit });
|
|
186
|
-
return { output: result.documents };
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
__decorate([
|
|
190
|
-
prop({
|
|
191
|
-
type: "collection",
|
|
192
|
-
default: {
|
|
193
|
-
type: "collection",
|
|
194
|
-
name: ""
|
|
195
|
-
},
|
|
196
|
-
title: "Collection",
|
|
197
|
-
description: "The collection to peek"
|
|
198
|
-
})
|
|
199
|
-
], PeekNode.prototype, "collection", void 0);
|
|
200
|
-
__decorate([
|
|
201
|
-
prop({
|
|
202
|
-
type: "int",
|
|
203
|
-
default: 100,
|
|
204
|
-
title: "Limit",
|
|
205
|
-
description: "The limit of the documents to peek"
|
|
206
|
-
})
|
|
207
|
-
], PeekNode.prototype, "limit", void 0);
|
|
208
|
-
// ---------------------------------------------------------------------------
|
|
209
|
-
// 5. IndexImageNode
|
|
210
|
-
// ---------------------------------------------------------------------------
|
|
211
|
-
export class IndexImageNode extends BaseNode {
|
|
212
|
-
static nodeType = "vector.IndexImage";
|
|
213
|
-
static title = "Index Image";
|
|
214
|
-
static description = "Index a list of image assets or files.\n vector, embedding, collection, RAG, index, image, batch";
|
|
215
|
-
async process() {
|
|
216
|
-
const collectionInput = (this.collection ??
|
|
217
|
-
this.collection ?? { name: "" });
|
|
218
|
-
const name = collectionInput.name ?? "";
|
|
219
|
-
if (!name.trim())
|
|
220
|
-
throw new Error("Collection name cannot be empty");
|
|
221
|
-
const image = (this.image ?? this.image ?? {});
|
|
222
|
-
const indexId = String(this.index_id ?? this.index_id ?? "");
|
|
223
|
-
const metadataRaw = (this.metadata ?? this.metadata ?? {});
|
|
224
|
-
const doUpsert = Boolean(this.upsert ?? this.upsert ?? false);
|
|
225
|
-
// Resolve document ID: prefer explicit index_id, then document_id field on image ref
|
|
226
|
-
const resolvedId = indexId.trim() ||
|
|
227
|
-
String(image.document_id ?? "").trim();
|
|
228
|
-
if (!resolvedId) {
|
|
229
|
-
throw new Error("document_id cannot be empty for image. Provide index_id or ensure image has a document_id.");
|
|
230
|
-
}
|
|
231
|
-
// Obtain image URI — TS environment does not have PIL; pass uri as document
|
|
232
|
-
const uri = String(image.uri ?? image.asset_id ?? "");
|
|
233
|
-
if (!uri) {
|
|
234
|
-
throw new Error("Image reference must have a uri or asset_id");
|
|
235
|
-
}
|
|
236
|
-
// Flatten metadata to Record<string, string | number | boolean>
|
|
237
|
-
const metadata = {};
|
|
238
|
-
for (const [k, v] of Object.entries(metadataRaw)) {
|
|
239
|
-
if (typeof v === "string" ||
|
|
240
|
-
typeof v === "number" ||
|
|
241
|
-
typeof v === "boolean") {
|
|
242
|
-
metadata[k] = v;
|
|
243
|
-
}
|
|
244
|
-
else {
|
|
245
|
-
metadata[k] = String(v);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
const collection = await getCollection(name);
|
|
249
|
-
if (doUpsert) {
|
|
250
|
-
await collection.upsert({
|
|
251
|
-
ids: [resolvedId],
|
|
252
|
-
uris: [uri],
|
|
253
|
-
metadatas: [metadata]
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
else {
|
|
257
|
-
await collection.add({
|
|
258
|
-
ids: [resolvedId],
|
|
259
|
-
uris: [uri],
|
|
260
|
-
metadatas: [metadata]
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
return { output: null };
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
__decorate([
|
|
267
|
-
prop({
|
|
268
|
-
type: "collection",
|
|
269
|
-
default: {
|
|
270
|
-
type: "collection",
|
|
271
|
-
name: ""
|
|
272
|
-
},
|
|
273
|
-
title: "Collection",
|
|
274
|
-
description: "The collection to index"
|
|
275
|
-
})
|
|
276
|
-
], IndexImageNode.prototype, "collection", void 0);
|
|
277
|
-
__decorate([
|
|
278
|
-
prop({
|
|
279
|
-
type: "image",
|
|
280
|
-
default: [],
|
|
281
|
-
title: "Image",
|
|
282
|
-
description: "List of image assets to index"
|
|
283
|
-
})
|
|
284
|
-
], IndexImageNode.prototype, "image", void 0);
|
|
285
|
-
__decorate([
|
|
286
|
-
prop({
|
|
287
|
-
type: "str",
|
|
288
|
-
default: "",
|
|
289
|
-
title: "Index Id",
|
|
290
|
-
description: "The ID to associate with the image, defaults to the URI of the image"
|
|
291
|
-
})
|
|
292
|
-
], IndexImageNode.prototype, "index_id", void 0);
|
|
293
|
-
__decorate([
|
|
294
|
-
prop({
|
|
295
|
-
type: "dict",
|
|
296
|
-
default: {},
|
|
297
|
-
title: "Metadata",
|
|
298
|
-
description: "The metadata to associate with the image"
|
|
299
|
-
})
|
|
300
|
-
], IndexImageNode.prototype, "metadata", void 0);
|
|
301
|
-
__decorate([
|
|
302
|
-
prop({
|
|
303
|
-
type: "bool",
|
|
304
|
-
default: false,
|
|
305
|
-
title: "Upsert",
|
|
306
|
-
description: "Whether to upsert the images"
|
|
307
|
-
})
|
|
308
|
-
], IndexImageNode.prototype, "upsert", void 0);
|
|
309
|
-
// ---------------------------------------------------------------------------
|
|
310
|
-
// 6. IndexEmbeddingNode
|
|
311
|
-
// ---------------------------------------------------------------------------
|
|
312
|
-
export class IndexEmbeddingNode extends BaseNode {
|
|
313
|
-
static nodeType = "vector.IndexEmbedding";
|
|
314
|
-
static title = "Index Embedding";
|
|
315
|
-
static description = "Index a single embedding vector into a collection with optional metadata. Creates a searchable entry that can be queried for similarity matching.\n vector, index, embedding, storage, RAG";
|
|
316
|
-
async process() {
|
|
317
|
-
const collectionInput = (this.collection ??
|
|
318
|
-
this.collection ?? { name: "" });
|
|
319
|
-
const name = collectionInput.name ?? "";
|
|
320
|
-
if (!name.trim())
|
|
321
|
-
throw new Error("Collection name cannot be empty");
|
|
322
|
-
const embeddingRaw = this.embedding ?? this.embedding;
|
|
323
|
-
const indexId = this.index_id ?? this.index_id ?? "";
|
|
324
|
-
const metadataRaw = this.metadata ?? this.metadata ?? {};
|
|
325
|
-
// embeddingRaw may be a flat number[] (single embedding) or number[][] (batch)
|
|
326
|
-
// or an NPArray-like object with a `data` field
|
|
327
|
-
let embeddings;
|
|
328
|
-
if (Array.isArray(embeddingRaw)) {
|
|
329
|
-
if (embeddingRaw.length === 0)
|
|
330
|
-
throw new Error("The embedding cannot be empty");
|
|
331
|
-
if (typeof embeddingRaw[0] === "number") {
|
|
332
|
-
// single 1-D array
|
|
333
|
-
embeddings = [embeddingRaw];
|
|
334
|
-
}
|
|
335
|
-
else {
|
|
336
|
-
embeddings = embeddingRaw;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
else if (embeddingRaw && typeof embeddingRaw === "object") {
|
|
340
|
-
// NPArray-like
|
|
341
|
-
const obj = embeddingRaw;
|
|
342
|
-
const data = obj.data ?? obj.array ?? obj.embedding;
|
|
343
|
-
if (Array.isArray(data)) {
|
|
344
|
-
if (typeof data[0] === "number") {
|
|
345
|
-
embeddings = [data];
|
|
346
|
-
}
|
|
347
|
-
else {
|
|
348
|
-
embeddings = data;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
else {
|
|
352
|
-
throw new Error("Cannot extract embedding data from provided object");
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
else {
|
|
356
|
-
throw new Error("The embedding cannot be empty");
|
|
357
|
-
}
|
|
358
|
-
if (Array.isArray(indexId)) {
|
|
359
|
-
// Batch mode
|
|
360
|
-
if (indexId.length === 0)
|
|
361
|
-
throw new Error("The IDs list cannot be empty");
|
|
362
|
-
if (indexId.length !== embeddings.length) {
|
|
363
|
-
throw new Error(`Number of IDs (${indexId.length}) must match number of embeddings (${embeddings.length})`);
|
|
364
|
-
}
|
|
365
|
-
let metadatas;
|
|
366
|
-
if (Array.isArray(metadataRaw)) {
|
|
367
|
-
if (metadataRaw.length !== indexId.length) {
|
|
368
|
-
throw new Error(`Number of IDs (${indexId.length}) must match number of metadatas (${metadataRaw.length})`);
|
|
369
|
-
}
|
|
370
|
-
metadatas = metadataRaw.map(flattenMetadata);
|
|
371
|
-
}
|
|
372
|
-
else {
|
|
373
|
-
const flat = flattenMetadata(metadataRaw);
|
|
374
|
-
metadatas = Array(indexId.length).fill(flat);
|
|
375
|
-
}
|
|
376
|
-
const collection = await getCollection(name);
|
|
377
|
-
await collection.add({
|
|
378
|
-
ids: indexId,
|
|
379
|
-
embeddings,
|
|
380
|
-
metadatas
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
else {
|
|
384
|
-
// Single mode
|
|
385
|
-
const idStr = String(indexId);
|
|
386
|
-
if (!idStr.trim())
|
|
387
|
-
throw new Error("The ID cannot be empty");
|
|
388
|
-
const flat = flattenMetadata((Array.isArray(metadataRaw) ? metadataRaw[0] : metadataRaw));
|
|
389
|
-
const collection = await getCollection(name);
|
|
390
|
-
await collection.add({
|
|
391
|
-
ids: [idStr],
|
|
392
|
-
embeddings: [embeddings[0]],
|
|
393
|
-
metadatas: [flat]
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
return { output: null };
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
__decorate([
|
|
400
|
-
prop({
|
|
401
|
-
type: "collection",
|
|
402
|
-
default: {
|
|
403
|
-
type: "collection",
|
|
404
|
-
name: ""
|
|
405
|
-
},
|
|
406
|
-
title: "Collection",
|
|
407
|
-
description: "The collection to index"
|
|
408
|
-
})
|
|
409
|
-
], IndexEmbeddingNode.prototype, "collection", void 0);
|
|
410
|
-
__decorate([
|
|
411
|
-
prop({
|
|
412
|
-
type: "list",
|
|
413
|
-
default: {
|
|
414
|
-
type: "list",
|
|
415
|
-
value: null,
|
|
416
|
-
dtype: "<i8",
|
|
417
|
-
shape: [1]
|
|
418
|
-
},
|
|
419
|
-
title: "Embedding",
|
|
420
|
-
description: "The embedding to index"
|
|
421
|
-
})
|
|
422
|
-
], IndexEmbeddingNode.prototype, "embedding", void 0);
|
|
423
|
-
__decorate([
|
|
424
|
-
prop({
|
|
425
|
-
type: "union[str, list[str]]",
|
|
426
|
-
default: "",
|
|
427
|
-
title: "Index Id",
|
|
428
|
-
description: "The ID to associate with the embedding"
|
|
429
|
-
})
|
|
430
|
-
], IndexEmbeddingNode.prototype, "index_id", void 0);
|
|
431
|
-
__decorate([
|
|
432
|
-
prop({
|
|
433
|
-
type: "union[dict, list[dict]]",
|
|
434
|
-
default: {},
|
|
435
|
-
title: "Metadata",
|
|
436
|
-
description: "The metadata to associate with the embedding"
|
|
437
|
-
})
|
|
438
|
-
], IndexEmbeddingNode.prototype, "metadata", void 0);
|
|
439
|
-
function flattenMetadata(obj) {
|
|
440
|
-
const result = {};
|
|
441
|
-
for (const [k, v] of Object.entries(obj ?? {})) {
|
|
442
|
-
if (typeof v === "string" ||
|
|
443
|
-
typeof v === "number" ||
|
|
444
|
-
typeof v === "boolean") {
|
|
445
|
-
result[k] = v;
|
|
446
|
-
}
|
|
447
|
-
else if (v !== null && v !== undefined) {
|
|
448
|
-
result[k] = String(v);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
return result;
|
|
452
|
-
}
|
|
453
|
-
// ---------------------------------------------------------------------------
|
|
454
|
-
// 7. IndexTextChunkNode
|
|
455
|
-
// ---------------------------------------------------------------------------
|
|
456
|
-
export class IndexTextChunkNode extends BaseNode {
|
|
457
|
-
static nodeType = "vector.IndexTextChunk";
|
|
458
|
-
static title = "Index Text Chunk";
|
|
459
|
-
static description = "Index a single text chunk.\n vector, embedding, collection, RAG, index, text, chunk";
|
|
460
|
-
async process() {
|
|
461
|
-
const collectionInput = (this.collection ??
|
|
462
|
-
this.collection ?? { name: "" });
|
|
463
|
-
const name = collectionInput.name ?? "";
|
|
464
|
-
if (!name.trim())
|
|
465
|
-
throw new Error("Collection name cannot be empty");
|
|
466
|
-
const documentId = String(this.document_id ?? this.document_id ?? "");
|
|
467
|
-
if (!documentId.trim())
|
|
468
|
-
throw new Error("The document ID cannot be empty");
|
|
469
|
-
const text = String(this.text ?? this.text ?? "");
|
|
470
|
-
const metadataRaw = (this.metadata ?? this.metadata ?? {});
|
|
471
|
-
const collection = await getCollection(name);
|
|
472
|
-
await collection.add({
|
|
473
|
-
ids: [documentId],
|
|
474
|
-
documents: [text],
|
|
475
|
-
metadatas: [flattenMetadata(metadataRaw)]
|
|
476
|
-
});
|
|
477
|
-
return { output: null };
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
__decorate([
|
|
481
|
-
prop({
|
|
482
|
-
type: "collection",
|
|
483
|
-
default: {
|
|
484
|
-
type: "collection",
|
|
485
|
-
name: ""
|
|
486
|
-
},
|
|
487
|
-
title: "Collection",
|
|
488
|
-
description: "The collection to index"
|
|
489
|
-
})
|
|
490
|
-
], IndexTextChunkNode.prototype, "collection", void 0);
|
|
491
|
-
__decorate([
|
|
492
|
-
prop({
|
|
493
|
-
type: "str",
|
|
494
|
-
default: "",
|
|
495
|
-
title: "Document Id",
|
|
496
|
-
description: "The document ID to associate with the text chunk"
|
|
497
|
-
})
|
|
498
|
-
], IndexTextChunkNode.prototype, "document_id", void 0);
|
|
499
|
-
__decorate([
|
|
500
|
-
prop({
|
|
501
|
-
type: "str",
|
|
502
|
-
default: "",
|
|
503
|
-
title: "Text",
|
|
504
|
-
description: "The text to index"
|
|
505
|
-
})
|
|
506
|
-
], IndexTextChunkNode.prototype, "text", void 0);
|
|
507
|
-
__decorate([
|
|
508
|
-
prop({
|
|
509
|
-
type: "dict",
|
|
510
|
-
default: {},
|
|
511
|
-
title: "Metadata",
|
|
512
|
-
description: "The metadata to associate with the text chunk"
|
|
513
|
-
})
|
|
514
|
-
], IndexTextChunkNode.prototype, "metadata", void 0);
|
|
515
|
-
export class IndexAggregatedTextNode extends BaseNode {
|
|
516
|
-
static nodeType = "vector.IndexAggregatedText";
|
|
517
|
-
static title = "Index Aggregated Text";
|
|
518
|
-
static description = "Index multiple text chunks at once with aggregated embeddings from Ollama.\n vector, embedding, collection, RAG, index, text, chunk, batch, ollama";
|
|
519
|
-
async process() {
|
|
520
|
-
const collectionInput = (this.collection ??
|
|
521
|
-
this.collection ?? { name: "" });
|
|
522
|
-
const name = collectionInput.name ?? "";
|
|
523
|
-
if (!name.trim())
|
|
524
|
-
throw new Error("Collection name cannot be empty");
|
|
525
|
-
const document = String(this.document ?? this.document ?? "");
|
|
526
|
-
const documentId = String(this.document_id ?? this.document_id ?? "");
|
|
527
|
-
const metadataRaw = (this.metadata ?? this.metadata ?? {});
|
|
528
|
-
const textChunksRaw = (this.text_chunks ?? this.text_chunks ?? []);
|
|
529
|
-
const aggregation = String(this.aggregation ?? this.aggregation ?? "mean");
|
|
530
|
-
if (!documentId.trim())
|
|
531
|
-
throw new Error("The document ID cannot be empty");
|
|
532
|
-
if (!document.trim())
|
|
533
|
-
throw new Error("The document cannot be empty");
|
|
534
|
-
if (textChunksRaw.length === 0)
|
|
535
|
-
throw new Error("The text chunks cannot be empty");
|
|
536
|
-
// Retrieve the collection to get the embedding model name
|
|
537
|
-
const collection = await getCollection(name);
|
|
538
|
-
const model = collection.metadata
|
|
539
|
-
?.embedding_model;
|
|
540
|
-
if (!model)
|
|
541
|
-
throw new Error("The collection does not have an embedding_model in its metadata");
|
|
542
|
-
// Extract plain text from each chunk
|
|
543
|
-
const texts = textChunksRaw.map((chunk) => typeof chunk === "string" ? chunk : chunk.text);
|
|
544
|
-
// Compute embeddings via Ollama
|
|
545
|
-
const embeddings = [];
|
|
546
|
-
for (const text of texts) {
|
|
547
|
-
const embedding = await getOllamaEmbedding(model, text);
|
|
548
|
-
embeddings.push(embedding);
|
|
549
|
-
}
|
|
550
|
-
// Aggregate embeddings
|
|
551
|
-
const dim = embeddings[0].length;
|
|
552
|
-
const aggregated = new Array(dim).fill(0);
|
|
553
|
-
if (aggregation === "mean" || aggregation === "sum") {
|
|
554
|
-
for (const emb of embeddings) {
|
|
555
|
-
for (let i = 0; i < dim; i++) {
|
|
556
|
-
aggregated[i] += emb[i];
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
if (aggregation === "mean") {
|
|
560
|
-
for (let i = 0; i < dim; i++) {
|
|
561
|
-
aggregated[i] /= embeddings.length;
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
else if (aggregation === "max") {
|
|
566
|
-
for (let i = 0; i < dim; i++) {
|
|
567
|
-
aggregated[i] = embeddings[0][i];
|
|
568
|
-
}
|
|
569
|
-
for (let j = 1; j < embeddings.length; j++) {
|
|
570
|
-
for (let i = 0; i < dim; i++) {
|
|
571
|
-
aggregated[i] = Math.max(aggregated[i], embeddings[j][i]);
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
else if (aggregation === "min") {
|
|
576
|
-
for (let i = 0; i < dim; i++) {
|
|
577
|
-
aggregated[i] = embeddings[0][i];
|
|
578
|
-
}
|
|
579
|
-
for (let j = 1; j < embeddings.length; j++) {
|
|
580
|
-
for (let i = 0; i < dim; i++) {
|
|
581
|
-
aggregated[i] = Math.min(aggregated[i], embeddings[j][i]);
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
else {
|
|
586
|
-
throw new Error(`Invalid aggregation method: ${aggregation}`);
|
|
587
|
-
}
|
|
588
|
-
const flat = flattenMetadata(metadataRaw);
|
|
589
|
-
await collection.add({
|
|
590
|
-
ids: [documentId],
|
|
591
|
-
documents: [document],
|
|
592
|
-
embeddings: [aggregated],
|
|
593
|
-
metadatas: Object.keys(flat).length > 0 ? [flat] : undefined
|
|
594
|
-
});
|
|
595
|
-
return { output: null };
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
__decorate([
|
|
599
|
-
prop({
|
|
600
|
-
type: "collection",
|
|
601
|
-
default: {
|
|
602
|
-
type: "collection",
|
|
603
|
-
name: ""
|
|
604
|
-
},
|
|
605
|
-
title: "Collection",
|
|
606
|
-
description: "The collection to index"
|
|
607
|
-
})
|
|
608
|
-
], IndexAggregatedTextNode.prototype, "collection", void 0);
|
|
609
|
-
__decorate([
|
|
610
|
-
prop({
|
|
611
|
-
type: "str",
|
|
612
|
-
default: "",
|
|
613
|
-
title: "Document",
|
|
614
|
-
description: "The document to index"
|
|
615
|
-
})
|
|
616
|
-
], IndexAggregatedTextNode.prototype, "document", void 0);
|
|
617
|
-
__decorate([
|
|
618
|
-
prop({
|
|
619
|
-
type: "str",
|
|
620
|
-
default: "",
|
|
621
|
-
title: "Document Id",
|
|
622
|
-
description: "The document ID to associate with the text"
|
|
623
|
-
})
|
|
624
|
-
], IndexAggregatedTextNode.prototype, "document_id", void 0);
|
|
625
|
-
__decorate([
|
|
626
|
-
prop({
|
|
627
|
-
type: "dict",
|
|
628
|
-
default: {},
|
|
629
|
-
title: "Metadata",
|
|
630
|
-
description: "The metadata to associate with the text"
|
|
631
|
-
})
|
|
632
|
-
], IndexAggregatedTextNode.prototype, "metadata", void 0);
|
|
633
|
-
__decorate([
|
|
634
|
-
prop({
|
|
635
|
-
type: "list[union[text_chunk, str]]",
|
|
636
|
-
default: [],
|
|
637
|
-
title: "Text Chunks",
|
|
638
|
-
description: "List of text chunks to index"
|
|
639
|
-
})
|
|
640
|
-
], IndexAggregatedTextNode.prototype, "text_chunks", void 0);
|
|
641
|
-
__decorate([
|
|
642
|
-
prop({
|
|
643
|
-
type: "enum",
|
|
644
|
-
default: "mean",
|
|
645
|
-
title: "Aggregation",
|
|
646
|
-
description: "The aggregation method to use for the embeddings.",
|
|
647
|
-
values: ["mean", "max", "min", "sum"]
|
|
648
|
-
})
|
|
649
|
-
], IndexAggregatedTextNode.prototype, "aggregation", void 0);
|
|
650
|
-
// ---------------------------------------------------------------------------
|
|
651
|
-
// 9. IndexStringNode
|
|
652
|
-
// ---------------------------------------------------------------------------
|
|
653
|
-
export class IndexStringNode extends BaseNode {
|
|
654
|
-
static nodeType = "vector.IndexString";
|
|
655
|
-
static title = "Index String";
|
|
656
|
-
static description = "Index a string with a Document ID to a collection.\n vector, embedding, collection, RAG, index, text, string";
|
|
657
|
-
async process() {
|
|
658
|
-
const collectionInput = (this.collection ??
|
|
659
|
-
this.collection ?? { name: "" });
|
|
660
|
-
const name = collectionInput.name ?? "";
|
|
661
|
-
if (!name.trim())
|
|
662
|
-
throw new Error("Collection name cannot be empty");
|
|
663
|
-
const documentId = String(this.document_id ?? this.document_id ?? "");
|
|
664
|
-
if (!documentId.trim())
|
|
665
|
-
throw new Error("The document ID cannot be empty");
|
|
666
|
-
const text = String(this.text ?? this.text ?? "");
|
|
667
|
-
const collection = await getCollection(name);
|
|
668
|
-
await collection.add({
|
|
669
|
-
ids: [documentId],
|
|
670
|
-
documents: [text]
|
|
671
|
-
});
|
|
672
|
-
return { output: null };
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
__decorate([
|
|
676
|
-
prop({
|
|
677
|
-
type: "collection",
|
|
678
|
-
default: {
|
|
679
|
-
type: "collection",
|
|
680
|
-
name: ""
|
|
681
|
-
},
|
|
682
|
-
title: "Collection",
|
|
683
|
-
description: "The collection to index"
|
|
684
|
-
})
|
|
685
|
-
], IndexStringNode.prototype, "collection", void 0);
|
|
686
|
-
__decorate([
|
|
687
|
-
prop({
|
|
688
|
-
type: "str",
|
|
689
|
-
default: "",
|
|
690
|
-
title: "Text",
|
|
691
|
-
description: "Text content to index"
|
|
692
|
-
})
|
|
693
|
-
], IndexStringNode.prototype, "text", void 0);
|
|
694
|
-
__decorate([
|
|
695
|
-
prop({
|
|
696
|
-
type: "str",
|
|
697
|
-
default: "",
|
|
698
|
-
title: "Document Id",
|
|
699
|
-
description: "Document ID to associate with the text content"
|
|
700
|
-
})
|
|
701
|
-
], IndexStringNode.prototype, "document_id", void 0);
|
|
702
|
-
__decorate([
|
|
703
|
-
prop({
|
|
704
|
-
type: "dict",
|
|
705
|
-
default: {},
|
|
706
|
-
title: "Metadata",
|
|
707
|
-
description: "The metadata to associate with the text"
|
|
708
|
-
})
|
|
709
|
-
], IndexStringNode.prototype, "metadata", void 0);
|
|
710
|
-
// ---------------------------------------------------------------------------
|
|
711
|
-
// 10. QueryImageNode
|
|
712
|
-
// ---------------------------------------------------------------------------
|
|
713
|
-
export class QueryImageNode extends BaseNode {
|
|
714
|
-
static nodeType = "vector.QueryImage";
|
|
715
|
-
static title = "Query Image";
|
|
716
|
-
static description = "Query the index for similar images.\n vector, RAG, query, image, search, similarity";
|
|
717
|
-
static metadataOutputTypes = {
|
|
718
|
-
ids: "list[str]",
|
|
719
|
-
documents: "list[str]",
|
|
720
|
-
metadatas: "list[dict]",
|
|
721
|
-
distances: "list[float]"
|
|
722
|
-
};
|
|
723
|
-
async process() {
|
|
724
|
-
const collectionInput = (this.collection ??
|
|
725
|
-
this.collection ?? { name: "" });
|
|
726
|
-
const name = collectionInput.name ?? "";
|
|
727
|
-
if (!name.trim())
|
|
728
|
-
throw new Error("Collection name cannot be empty");
|
|
729
|
-
const image = (this.image ?? this.image ?? {});
|
|
730
|
-
const uri = String(image.uri ?? image.asset_id ?? "");
|
|
731
|
-
if (!uri)
|
|
732
|
-
throw new Error("Image is not connected (no uri or asset_id)");
|
|
733
|
-
const nResults = Number(this.n_results ?? this.n_results ?? 1);
|
|
734
|
-
const collection = await getCollection(name);
|
|
735
|
-
const result = await collection.query({
|
|
736
|
-
queryURIs: [uri],
|
|
737
|
-
nResults,
|
|
738
|
-
include: ["documents", "metadatas", "distances"]
|
|
739
|
-
});
|
|
740
|
-
if (!result.ids)
|
|
741
|
-
throw new Error("Ids are not returned");
|
|
742
|
-
if (!result.documents)
|
|
743
|
-
throw new Error("Documents are not returned");
|
|
744
|
-
if (!result.metadatas)
|
|
745
|
-
throw new Error("Metadatas are not returned");
|
|
746
|
-
if (!result.distances)
|
|
747
|
-
throw new Error("Distances are not returned");
|
|
748
|
-
// Sort by ID (matching Python behavior)
|
|
749
|
-
const combined = result.ids[0].map((id, idx) => ({
|
|
750
|
-
id: String(id),
|
|
751
|
-
document: result.documents[0][idx] ?? "",
|
|
752
|
-
metadata: (result.metadatas[0][idx] ?? {}),
|
|
753
|
-
distance: result.distances[0][idx] ?? 0
|
|
754
|
-
}));
|
|
755
|
-
combined.sort((a, b) => a.id.localeCompare(b.id));
|
|
756
|
-
return {
|
|
757
|
-
output: {
|
|
758
|
-
ids: combined.map((r) => r.id),
|
|
759
|
-
documents: combined.map((r) => r.document),
|
|
760
|
-
metadatas: combined.map((r) => r.metadata),
|
|
761
|
-
distances: combined.map((r) => r.distance)
|
|
762
|
-
}
|
|
763
|
-
};
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
__decorate([
|
|
767
|
-
prop({
|
|
768
|
-
type: "collection",
|
|
769
|
-
default: {
|
|
770
|
-
type: "collection",
|
|
771
|
-
name: ""
|
|
772
|
-
},
|
|
773
|
-
title: "Collection",
|
|
774
|
-
description: "The collection to query"
|
|
775
|
-
})
|
|
776
|
-
], QueryImageNode.prototype, "collection", void 0);
|
|
777
|
-
__decorate([
|
|
778
|
-
prop({
|
|
779
|
-
type: "image",
|
|
780
|
-
default: {
|
|
781
|
-
type: "image",
|
|
782
|
-
uri: "",
|
|
783
|
-
asset_id: null,
|
|
784
|
-
data: null,
|
|
785
|
-
metadata: null
|
|
786
|
-
},
|
|
787
|
-
title: "Image",
|
|
788
|
-
description: "The image to query"
|
|
789
|
-
})
|
|
790
|
-
], QueryImageNode.prototype, "image", void 0);
|
|
791
|
-
__decorate([
|
|
792
|
-
prop({
|
|
793
|
-
type: "int",
|
|
794
|
-
default: 1,
|
|
795
|
-
title: "N Results",
|
|
796
|
-
description: "The number of results to return"
|
|
797
|
-
})
|
|
798
|
-
], QueryImageNode.prototype, "n_results", void 0);
|
|
799
|
-
// ---------------------------------------------------------------------------
|
|
800
|
-
// 11. QueryTextNode
|
|
801
|
-
// ---------------------------------------------------------------------------
|
|
802
|
-
export class QueryTextNode extends BaseNode {
|
|
803
|
-
static nodeType = "vector.QueryText";
|
|
804
|
-
static title = "Query Text";
|
|
805
|
-
static description = "Query the index for similar text.\n vector, RAG, query, text, search, similarity";
|
|
806
|
-
static metadataOutputTypes = {
|
|
807
|
-
ids: "list[str]",
|
|
808
|
-
documents: "list[str]",
|
|
809
|
-
metadatas: "list[dict]",
|
|
810
|
-
distances: "list[float]"
|
|
811
|
-
};
|
|
812
|
-
async process() {
|
|
813
|
-
const collectionInput = (this.collection ??
|
|
814
|
-
this.collection ?? { name: "" });
|
|
815
|
-
const name = collectionInput.name ?? "";
|
|
816
|
-
if (!name.trim())
|
|
817
|
-
throw new Error("Collection name cannot be empty");
|
|
818
|
-
const text = String(this.text ?? this.text ?? "");
|
|
819
|
-
const nResults = Number(this.n_results ?? this.n_results ?? 1);
|
|
820
|
-
const collection = await getCollection(name);
|
|
821
|
-
const result = await collection.query({
|
|
822
|
-
queryTexts: [text],
|
|
823
|
-
nResults,
|
|
824
|
-
include: ["documents", "metadatas", "distances"]
|
|
825
|
-
});
|
|
826
|
-
if (!result.ids)
|
|
827
|
-
throw new Error("Ids are not returned");
|
|
828
|
-
if (!result.documents)
|
|
829
|
-
throw new Error("Documents are not returned");
|
|
830
|
-
if (!result.metadatas)
|
|
831
|
-
throw new Error("Metadatas are not returned");
|
|
832
|
-
if (!result.distances)
|
|
833
|
-
throw new Error("Distances are not returned");
|
|
834
|
-
// Sort by ID (matching Python behavior)
|
|
835
|
-
const combined = result.ids[0].map((id, idx) => ({
|
|
836
|
-
id: String(id),
|
|
837
|
-
document: result.documents[0][idx] ?? "",
|
|
838
|
-
metadata: (result.metadatas[0][idx] ?? {}),
|
|
839
|
-
distance: result.distances[0][idx] ?? 0
|
|
840
|
-
}));
|
|
841
|
-
combined.sort((a, b) => a.id.localeCompare(b.id));
|
|
842
|
-
return {
|
|
843
|
-
output: {
|
|
844
|
-
ids: combined.map((r) => r.id),
|
|
845
|
-
documents: combined.map((r) => r.document),
|
|
846
|
-
metadatas: combined.map((r) => r.metadata),
|
|
847
|
-
distances: combined.map((r) => r.distance)
|
|
848
|
-
}
|
|
849
|
-
};
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
__decorate([
|
|
853
|
-
prop({
|
|
854
|
-
type: "collection",
|
|
855
|
-
default: {
|
|
856
|
-
type: "collection",
|
|
857
|
-
name: ""
|
|
858
|
-
},
|
|
859
|
-
title: "Collection",
|
|
860
|
-
description: "The collection to query"
|
|
861
|
-
})
|
|
862
|
-
], QueryTextNode.prototype, "collection", void 0);
|
|
863
|
-
__decorate([
|
|
864
|
-
prop({
|
|
865
|
-
type: "str",
|
|
866
|
-
default: "",
|
|
867
|
-
title: "Text",
|
|
868
|
-
description: "The text to query"
|
|
869
|
-
})
|
|
870
|
-
], QueryTextNode.prototype, "text", void 0);
|
|
871
|
-
__decorate([
|
|
872
|
-
prop({
|
|
873
|
-
type: "int",
|
|
874
|
-
default: 1,
|
|
875
|
-
title: "N Results",
|
|
876
|
-
description: "The number of results to return"
|
|
877
|
-
})
|
|
878
|
-
], QueryTextNode.prototype, "n_results", void 0);
|
|
879
|
-
// ---------------------------------------------------------------------------
|
|
880
|
-
// 12. RemoveOverlapNode
|
|
881
|
-
// ---------------------------------------------------------------------------
|
|
882
|
-
export class RemoveOverlapNode extends BaseNode {
|
|
883
|
-
static nodeType = "vector.RemoveOverlap";
|
|
884
|
-
static title = "Remove Overlap";
|
|
885
|
-
static description = "Removes overlapping words between consecutive strings in a list. Splits text into words and matches word sequences for more accurate overlap detection.\n vector, RAG, query, text, processing, overlap, deduplication";
|
|
886
|
-
static metadataOutputTypes = {
|
|
887
|
-
documents: "list[str]"
|
|
888
|
-
};
|
|
889
|
-
_splitIntoWords(text) {
|
|
890
|
-
return text.split(/\s+/).filter((w) => w.length > 0);
|
|
891
|
-
}
|
|
892
|
-
_findWordOverlap(words1, words2, minOverlap) {
|
|
893
|
-
if (words1.length < minOverlap || words2.length < minOverlap)
|
|
894
|
-
return 0;
|
|
895
|
-
const maxCheck = Math.min(words1.length, words2.length);
|
|
896
|
-
for (let overlapSize = maxCheck; overlapSize >= minOverlap; overlapSize--) {
|
|
897
|
-
const tail = words1.slice(words1.length - overlapSize);
|
|
898
|
-
const head = words2.slice(0, overlapSize);
|
|
899
|
-
if (tail.every((w, i) => w === head[i])) {
|
|
900
|
-
return overlapSize;
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
return 0;
|
|
904
|
-
}
|
|
905
|
-
async process() {
|
|
906
|
-
const documents = (this.documents ?? this.documents ?? []);
|
|
907
|
-
const minOverlapWords = Number(this.min_overlap_words ?? this.min_overlap_words ?? 2);
|
|
908
|
-
if (documents.length === 0) {
|
|
909
|
-
return { documents: [] };
|
|
910
|
-
}
|
|
911
|
-
const result = [documents[0]];
|
|
912
|
-
for (let i = 1; i < documents.length; i++) {
|
|
913
|
-
const prevWords = this._splitIntoWords(result[result.length - 1]);
|
|
914
|
-
const currWords = this._splitIntoWords(documents[i]);
|
|
915
|
-
const overlapWordCount = this._findWordOverlap(prevWords, currWords, minOverlapWords);
|
|
916
|
-
if (overlapWordCount > 0) {
|
|
917
|
-
const newText = currWords.slice(overlapWordCount).join(" ");
|
|
918
|
-
if (newText) {
|
|
919
|
-
result.push(newText);
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
else {
|
|
923
|
-
result.push(documents[i]);
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
return { documents: result };
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
__decorate([
|
|
930
|
-
prop({
|
|
931
|
-
type: "list[str]",
|
|
932
|
-
default: [],
|
|
933
|
-
title: "Documents",
|
|
934
|
-
description: "List of strings to process for overlap removal"
|
|
935
|
-
})
|
|
936
|
-
], RemoveOverlapNode.prototype, "documents", void 0);
|
|
937
|
-
__decorate([
|
|
938
|
-
prop({
|
|
939
|
-
type: "int",
|
|
940
|
-
default: 2,
|
|
941
|
-
title: "Min Overlap Words",
|
|
942
|
-
description: "Minimum number of words that must overlap to be considered"
|
|
943
|
-
})
|
|
944
|
-
], RemoveOverlapNode.prototype, "min_overlap_words", void 0);
|
|
945
|
-
// ---------------------------------------------------------------------------
|
|
946
|
-
// 13. HybridSearchNode
|
|
947
|
-
// ---------------------------------------------------------------------------
|
|
948
|
-
export class HybridSearchNode extends BaseNode {
|
|
949
|
-
static nodeType = "vector.HybridSearch";
|
|
950
|
-
static title = "Hybrid Search";
|
|
951
|
-
static description = "Hybrid search combining semantic and keyword-based search for better retrieval. Uses reciprocal rank fusion to combine results from both methods.\n vector, RAG, query, semantic, text, similarity";
|
|
952
|
-
static metadataOutputTypes = {
|
|
953
|
-
ids: "list[str]",
|
|
954
|
-
documents: "list[str]",
|
|
955
|
-
metadatas: "list[dict]",
|
|
956
|
-
distances: "list[float]",
|
|
957
|
-
scores: "list[float]"
|
|
958
|
-
};
|
|
959
|
-
_getKeywordQuery(text, minKeywordLength) {
|
|
960
|
-
const pattern = /[ ,.!?\-_=|]+/;
|
|
961
|
-
const queryTokens = text
|
|
962
|
-
.toLowerCase()
|
|
963
|
-
.split(pattern)
|
|
964
|
-
.map((t) => t.trim())
|
|
965
|
-
.filter((t) => t.length >= minKeywordLength);
|
|
966
|
-
if (queryTokens.length === 0)
|
|
967
|
-
return null;
|
|
968
|
-
if (queryTokens.length > 1) {
|
|
969
|
-
return { $or: queryTokens.map((token) => ({ $contains: token })) };
|
|
970
|
-
}
|
|
971
|
-
return { $contains: queryTokens[0] };
|
|
972
|
-
}
|
|
973
|
-
async process() {
|
|
974
|
-
const collectionInput = (this.collection ??
|
|
975
|
-
this.collection ?? { name: "" });
|
|
976
|
-
const name = collectionInput.name ?? "";
|
|
977
|
-
if (!name.trim())
|
|
978
|
-
throw new Error("Collection name cannot be empty");
|
|
979
|
-
const text = String(this.text ?? this.text ?? "");
|
|
980
|
-
if (!text.trim())
|
|
981
|
-
throw new Error("Search text cannot be empty");
|
|
982
|
-
const nResults = Number(this.n_results ?? this.n_results ?? 5);
|
|
983
|
-
const kConstant = Number(this.k_constant ?? this.k_constant ?? 60.0);
|
|
984
|
-
const minKeywordLength = Number(this.min_keyword_length ?? this.min_keyword_length ?? 3);
|
|
985
|
-
const collection = await getCollection(name);
|
|
986
|
-
// Semantic search
|
|
987
|
-
const semanticResult = await collection.query({
|
|
988
|
-
queryTexts: [text],
|
|
989
|
-
nResults: nResults * 2,
|
|
990
|
-
include: ["documents", "metadatas", "distances"]
|
|
991
|
-
});
|
|
992
|
-
// Keyword search
|
|
993
|
-
const keywordQuery = this._getKeywordQuery(text, minKeywordLength);
|
|
994
|
-
let keywordResult = semanticResult;
|
|
995
|
-
if (keywordQuery) {
|
|
996
|
-
keywordResult = await collection.query({
|
|
997
|
-
queryTexts: [text],
|
|
998
|
-
nResults: nResults * 2,
|
|
999
|
-
whereDocument: keywordQuery,
|
|
1000
|
-
include: ["documents", "metadatas", "distances"]
|
|
1001
|
-
});
|
|
1002
|
-
}
|
|
1003
|
-
// Validate
|
|
1004
|
-
for (const res of [semanticResult, keywordResult]) {
|
|
1005
|
-
if (!res.ids)
|
|
1006
|
-
throw new Error("Ids are not returned");
|
|
1007
|
-
if (!res.documents)
|
|
1008
|
-
throw new Error("Documents are not returned");
|
|
1009
|
-
if (!res.metadatas)
|
|
1010
|
-
throw new Error("Metadatas are not returned");
|
|
1011
|
-
if (!res.distances)
|
|
1012
|
-
throw new Error("Distances are not returned");
|
|
1013
|
-
}
|
|
1014
|
-
// Reciprocal rank fusion
|
|
1015
|
-
const combinedScores = new Map();
|
|
1016
|
-
const processResults = (ids, docs, metas, distances) => {
|
|
1017
|
-
ids.forEach((id, rank) => {
|
|
1018
|
-
const strId = String(id);
|
|
1019
|
-
const score = 1 / (rank + kConstant);
|
|
1020
|
-
if (combinedScores.has(strId)) {
|
|
1021
|
-
combinedScores.get(strId).score += score;
|
|
1022
|
-
}
|
|
1023
|
-
else {
|
|
1024
|
-
combinedScores.set(strId, {
|
|
1025
|
-
doc: docs[rank] ?? "",
|
|
1026
|
-
meta: (metas[rank] ?? {}),
|
|
1027
|
-
distance: distances[rank] ?? 0,
|
|
1028
|
-
score
|
|
1029
|
-
});
|
|
1030
|
-
}
|
|
1031
|
-
});
|
|
1032
|
-
};
|
|
1033
|
-
processResults(semanticResult.ids[0].map(String), semanticResult.documents[0], semanticResult.metadatas[0], semanticResult.distances[0]);
|
|
1034
|
-
processResults(keywordResult.ids[0].map(String), keywordResult.documents[0], keywordResult.metadatas[0], keywordResult.distances[0]);
|
|
1035
|
-
// Sort by combined score descending
|
|
1036
|
-
const sorted = [...combinedScores.entries()]
|
|
1037
|
-
.sort((a, b) => b[1].score - a[1].score)
|
|
1038
|
-
.slice(0, nResults);
|
|
1039
|
-
const resultIds = [];
|
|
1040
|
-
const resultDocs = [];
|
|
1041
|
-
const resultMetas = [];
|
|
1042
|
-
const resultDistances = [];
|
|
1043
|
-
const resultScores = [];
|
|
1044
|
-
for (const [id, data] of sorted) {
|
|
1045
|
-
resultIds.push(id);
|
|
1046
|
-
resultDocs.push(data.doc);
|
|
1047
|
-
resultMetas.push(data.meta);
|
|
1048
|
-
resultDistances.push(data.distance);
|
|
1049
|
-
resultScores.push(data.score);
|
|
1050
|
-
}
|
|
1051
|
-
return {
|
|
1052
|
-
ids: resultIds,
|
|
1053
|
-
documents: resultDocs,
|
|
1054
|
-
metadatas: resultMetas,
|
|
1055
|
-
distances: resultDistances,
|
|
1056
|
-
scores: resultScores
|
|
1057
|
-
};
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
|
-
__decorate([
|
|
1061
|
-
prop({
|
|
1062
|
-
type: "collection",
|
|
1063
|
-
default: {
|
|
1064
|
-
type: "collection",
|
|
1065
|
-
name: ""
|
|
1066
|
-
},
|
|
1067
|
-
title: "Collection",
|
|
1068
|
-
description: "The collection to query"
|
|
1069
|
-
})
|
|
1070
|
-
], HybridSearchNode.prototype, "collection", void 0);
|
|
1071
|
-
__decorate([
|
|
1072
|
-
prop({
|
|
1073
|
-
type: "str",
|
|
1074
|
-
default: "",
|
|
1075
|
-
title: "Text",
|
|
1076
|
-
description: "The text to query"
|
|
1077
|
-
})
|
|
1078
|
-
], HybridSearchNode.prototype, "text", void 0);
|
|
1079
|
-
__decorate([
|
|
1080
|
-
prop({
|
|
1081
|
-
type: "int",
|
|
1082
|
-
default: 5,
|
|
1083
|
-
title: "N Results",
|
|
1084
|
-
description: "The number of final results to return"
|
|
1085
|
-
})
|
|
1086
|
-
], HybridSearchNode.prototype, "n_results", void 0);
|
|
1087
|
-
__decorate([
|
|
1088
|
-
prop({
|
|
1089
|
-
type: "float",
|
|
1090
|
-
default: 60,
|
|
1091
|
-
title: "K Constant",
|
|
1092
|
-
description: "Constant for reciprocal rank fusion (default: 60.0)"
|
|
1093
|
-
})
|
|
1094
|
-
], HybridSearchNode.prototype, "k_constant", void 0);
|
|
1095
|
-
__decorate([
|
|
1096
|
-
prop({
|
|
1097
|
-
type: "int",
|
|
1098
|
-
default: 3,
|
|
1099
|
-
title: "Min Keyword Length",
|
|
1100
|
-
description: "Minimum length for keyword tokens"
|
|
1101
|
-
})
|
|
1102
|
-
], HybridSearchNode.prototype, "min_keyword_length", void 0);
|
|
1103
|
-
// ---------------------------------------------------------------------------
|
|
1104
|
-
// Export
|
|
1105
|
-
// ---------------------------------------------------------------------------
|
|
1106
|
-
export const VECTOR_NODES = [
|
|
1107
|
-
CollectionNode,
|
|
1108
|
-
CountNode,
|
|
1109
|
-
GetDocumentsNode,
|
|
1110
|
-
PeekNode,
|
|
1111
|
-
IndexImageNode,
|
|
1112
|
-
IndexEmbeddingNode,
|
|
1113
|
-
IndexTextChunkNode,
|
|
1114
|
-
IndexAggregatedTextNode,
|
|
1115
|
-
IndexStringNode,
|
|
1116
|
-
QueryImageNode,
|
|
1117
|
-
QueryTextNode,
|
|
1118
|
-
RemoveOverlapNode,
|
|
1119
|
-
HybridSearchNode
|
|
1120
|
-
];
|
|
1121
|
-
//# sourceMappingURL=vector.js.map
|