@superlinked/sie-llamaindex 0.1.8 → 0.1.10
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/index.cjs +179 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +182 -10
- package/dist/index.d.ts +182 -10
- package/dist/index.js +180 -32
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -21,12 +21,180 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
SIEEmbedding: () => SIEEmbedding,
|
|
24
|
-
|
|
24
|
+
SIENodePostprocessor: () => SIENodePostprocessor,
|
|
25
|
+
SIESparseEmbeddingFunction: () => SIESparseEmbeddingFunction,
|
|
26
|
+
createSIEExtractorTool: () => createSIEExtractorTool
|
|
25
27
|
});
|
|
26
28
|
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
var import_sie_sdk3 = require("@superlinked/sie-sdk");
|
|
30
|
+
var import_llamaindex3 = require("llamaindex");
|
|
31
|
+
|
|
32
|
+
// src/rerankers.ts
|
|
27
33
|
var import_sie_sdk = require("@superlinked/sie-sdk");
|
|
28
34
|
var import_llamaindex = require("llamaindex");
|
|
29
|
-
|
|
35
|
+
function extractQueryString(query) {
|
|
36
|
+
if (typeof query === "string") {
|
|
37
|
+
return query;
|
|
38
|
+
}
|
|
39
|
+
return query.filter(
|
|
40
|
+
(part) => "type" in part && part.type === "text"
|
|
41
|
+
).map((part) => part.text).join(" ");
|
|
42
|
+
}
|
|
43
|
+
var SIENodePostprocessor = class {
|
|
44
|
+
modelName;
|
|
45
|
+
topN;
|
|
46
|
+
_client;
|
|
47
|
+
_ownsClient;
|
|
48
|
+
baseUrl;
|
|
49
|
+
clientOptions;
|
|
50
|
+
constructor(options = {}) {
|
|
51
|
+
const {
|
|
52
|
+
baseUrl = "http://localhost:8080",
|
|
53
|
+
modelName = "jinaai/jina-reranker-v2-base-multilingual",
|
|
54
|
+
client,
|
|
55
|
+
topN,
|
|
56
|
+
gpu,
|
|
57
|
+
timeout = 18e4
|
|
58
|
+
} = options;
|
|
59
|
+
this.baseUrl = baseUrl;
|
|
60
|
+
this.modelName = modelName;
|
|
61
|
+
this.topN = topN;
|
|
62
|
+
this._client = client;
|
|
63
|
+
this._ownsClient = !client;
|
|
64
|
+
this.clientOptions = {
|
|
65
|
+
timeout,
|
|
66
|
+
gpu
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get or create the SIEClient.
|
|
71
|
+
*/
|
|
72
|
+
get client() {
|
|
73
|
+
if (!this._client) {
|
|
74
|
+
this._client = new import_sie_sdk.SIEClient(this.baseUrl, this.clientOptions);
|
|
75
|
+
}
|
|
76
|
+
return this._client;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Rerank nodes by relevance to query.
|
|
80
|
+
*
|
|
81
|
+
* @param nodes - Nodes with scores to rerank.
|
|
82
|
+
* @param query - Optional query string or MessageContent.
|
|
83
|
+
* @returns Reranked nodes with updated scores, sorted by relevance descending.
|
|
84
|
+
*/
|
|
85
|
+
async postprocessNodes(nodes, query) {
|
|
86
|
+
if (nodes.length === 0 || query === void 0) {
|
|
87
|
+
return nodes;
|
|
88
|
+
}
|
|
89
|
+
const queryText = extractQueryString(query);
|
|
90
|
+
if (!queryText) {
|
|
91
|
+
return nodes;
|
|
92
|
+
}
|
|
93
|
+
const queryItem = { text: queryText };
|
|
94
|
+
const docItems = nodes.map((n) => ({ text: n.node.getContent(import_llamaindex.MetadataMode.NONE) }));
|
|
95
|
+
const result = await this.client.score(this.modelName, queryItem, docItems);
|
|
96
|
+
const reranked = [];
|
|
97
|
+
for (const entry of result.scores) {
|
|
98
|
+
const idx = Number.parseInt(entry.itemId, 10);
|
|
99
|
+
const original = nodes[idx];
|
|
100
|
+
if (original) {
|
|
101
|
+
reranked.push({
|
|
102
|
+
node: original.node,
|
|
103
|
+
score: entry.score
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (this.topN !== void 0) {
|
|
108
|
+
return reranked.slice(0, this.topN);
|
|
109
|
+
}
|
|
110
|
+
return reranked;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Close the underlying client connection.
|
|
114
|
+
*/
|
|
115
|
+
async close() {
|
|
116
|
+
if (this._client && this._ownsClient) {
|
|
117
|
+
await this._client.close();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// src/extractors.ts
|
|
123
|
+
var import_sie_sdk2 = require("@superlinked/sie-sdk");
|
|
124
|
+
var import_llamaindex2 = require("llamaindex");
|
|
125
|
+
var _SIEExtractor = class {
|
|
126
|
+
baseUrl;
|
|
127
|
+
modelName;
|
|
128
|
+
labels;
|
|
129
|
+
threshold;
|
|
130
|
+
clientOptions;
|
|
131
|
+
_client;
|
|
132
|
+
constructor(options) {
|
|
133
|
+
this.baseUrl = options.baseUrl ?? "http://localhost:8080";
|
|
134
|
+
this.modelName = options.modelName ?? "urchade/gliner_multi-v2.1";
|
|
135
|
+
this.labels = options.labels ?? ["person", "organization", "location"];
|
|
136
|
+
this.threshold = options.threshold;
|
|
137
|
+
this.clientOptions = {
|
|
138
|
+
timeout: options.timeout ?? 18e4,
|
|
139
|
+
gpu: options.gpu
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
get client() {
|
|
143
|
+
if (!this._client) {
|
|
144
|
+
this._client = new import_sie_sdk2.SIEClient(this.baseUrl, this.clientOptions);
|
|
145
|
+
}
|
|
146
|
+
return this._client;
|
|
147
|
+
}
|
|
148
|
+
async extract(text) {
|
|
149
|
+
const extractOptions = {
|
|
150
|
+
labels: this.labels
|
|
151
|
+
};
|
|
152
|
+
if (this.threshold !== void 0) {
|
|
153
|
+
extractOptions.threshold = this.threshold;
|
|
154
|
+
}
|
|
155
|
+
const result = await this.client.extract(this.modelName, { text }, extractOptions);
|
|
156
|
+
return JSON.stringify({
|
|
157
|
+
entities: result.entities.map((e) => ({
|
|
158
|
+
text: e.text,
|
|
159
|
+
label: e.label,
|
|
160
|
+
score: e.score,
|
|
161
|
+
...e.start !== void 0 && { start: e.start },
|
|
162
|
+
...e.end !== void 0 && { end: e.end }
|
|
163
|
+
})),
|
|
164
|
+
relations: result.relations.map((r) => ({
|
|
165
|
+
head: r.head,
|
|
166
|
+
tail: r.tail,
|
|
167
|
+
relation: r.relation,
|
|
168
|
+
score: r.score
|
|
169
|
+
})),
|
|
170
|
+
classifications: result.classifications.map((c) => ({
|
|
171
|
+
label: c.label,
|
|
172
|
+
score: c.score
|
|
173
|
+
})),
|
|
174
|
+
objects: result.objects.map((o) => ({
|
|
175
|
+
label: o.label,
|
|
176
|
+
score: o.score,
|
|
177
|
+
bbox: o.bbox
|
|
178
|
+
}))
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
function createSIEExtractorTool(options = {}) {
|
|
183
|
+
const labels = options.labels ?? ["person", "organization", "location"];
|
|
184
|
+
const name = options.name ?? "sie_extract";
|
|
185
|
+
const description = options.description ?? `Extract structured information from text. Finds entities of types: ${labels.join(", ")}. Returns entities, relations, classifications, and detected objects.`;
|
|
186
|
+
const extractor = new _SIEExtractor(options);
|
|
187
|
+
async function extract(input) {
|
|
188
|
+
return extractor.extract(input.text);
|
|
189
|
+
}
|
|
190
|
+
return import_llamaindex2.FunctionTool.from(extract, {
|
|
191
|
+
name,
|
|
192
|
+
description
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// src/index.ts
|
|
197
|
+
var SIEEmbedding = class extends import_llamaindex3.BaseEmbedding {
|
|
30
198
|
modelName;
|
|
31
199
|
instruction;
|
|
32
200
|
outputDtype;
|
|
@@ -49,7 +217,7 @@ var SIEEmbedding = class extends import_llamaindex.BaseEmbedding {
|
|
|
49
217
|
isQuery: false
|
|
50
218
|
};
|
|
51
219
|
const results = await this.client.encode(this.modelName, items, options);
|
|
52
|
-
return results.map((result) =>
|
|
220
|
+
return results.map((result) => (0, import_sie_sdk3.denseEmbedding)(result));
|
|
53
221
|
};
|
|
54
222
|
constructor(options = {}) {
|
|
55
223
|
super();
|
|
@@ -79,7 +247,7 @@ var SIEEmbedding = class extends import_llamaindex.BaseEmbedding {
|
|
|
79
247
|
*/
|
|
80
248
|
get client() {
|
|
81
249
|
if (!this._client) {
|
|
82
|
-
this._client = new
|
|
250
|
+
this._client = new import_sie_sdk3.SIEClient(this.baseUrl, this.clientOptions);
|
|
83
251
|
}
|
|
84
252
|
return this._client;
|
|
85
253
|
}
|
|
@@ -97,17 +265,7 @@ var SIEEmbedding = class extends import_llamaindex.BaseEmbedding {
|
|
|
97
265
|
isQuery: false
|
|
98
266
|
};
|
|
99
267
|
const result = await this.client.encode(this.modelName, { text }, options);
|
|
100
|
-
return
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Extract dense embedding from encode result.
|
|
104
|
-
*/
|
|
105
|
-
extractDense(result) {
|
|
106
|
-
const dense = result.dense;
|
|
107
|
-
if (!dense) {
|
|
108
|
-
throw new Error("Encode result missing dense embedding");
|
|
109
|
-
}
|
|
110
|
-
return (0, import_sie_sdk.toNumberArray)(dense);
|
|
268
|
+
return (0, import_sie_sdk3.denseEmbedding)(result);
|
|
111
269
|
}
|
|
112
270
|
/**
|
|
113
271
|
* Close the underlying client connection.
|
|
@@ -142,7 +300,7 @@ var SIESparseEmbeddingFunction = class {
|
|
|
142
300
|
*/
|
|
143
301
|
get client() {
|
|
144
302
|
if (!this._client) {
|
|
145
|
-
this._client = new
|
|
303
|
+
this._client = new import_sie_sdk3.SIEClient(this.baseUrl, this.clientOptions);
|
|
146
304
|
}
|
|
147
305
|
return this._client;
|
|
148
306
|
}
|
|
@@ -165,7 +323,7 @@ var SIESparseEmbeddingFunction = class {
|
|
|
165
323
|
const indicesList = [];
|
|
166
324
|
const valuesList = [];
|
|
167
325
|
for (const result of results) {
|
|
168
|
-
const sparse =
|
|
326
|
+
const sparse = (0, import_sie_sdk3.sparseEmbedding)(result);
|
|
169
327
|
indicesList.push(sparse.indices);
|
|
170
328
|
valuesList.push(sparse.values);
|
|
171
329
|
}
|
|
@@ -190,25 +348,12 @@ var SIESparseEmbeddingFunction = class {
|
|
|
190
348
|
const indicesList = [];
|
|
191
349
|
const valuesList = [];
|
|
192
350
|
for (const result of results) {
|
|
193
|
-
const sparse =
|
|
351
|
+
const sparse = (0, import_sie_sdk3.sparseEmbedding)(result);
|
|
194
352
|
indicesList.push(sparse.indices);
|
|
195
353
|
valuesList.push(sparse.values);
|
|
196
354
|
}
|
|
197
355
|
return [indicesList, valuesList];
|
|
198
356
|
}
|
|
199
|
-
/**
|
|
200
|
-
* Extract sparse embedding from encode result.
|
|
201
|
-
*/
|
|
202
|
-
extractSparse(result) {
|
|
203
|
-
const sparse = result.sparse;
|
|
204
|
-
if (!sparse) {
|
|
205
|
-
return { indices: [], values: [] };
|
|
206
|
-
}
|
|
207
|
-
return {
|
|
208
|
-
indices: (0, import_sie_sdk.toNumberArray)(sparse.indices),
|
|
209
|
-
values: (0, import_sie_sdk.toNumberArray)(sparse.values)
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
357
|
/**
|
|
213
358
|
* Close the underlying client connection.
|
|
214
359
|
*/
|
|
@@ -221,6 +366,8 @@ var SIESparseEmbeddingFunction = class {
|
|
|
221
366
|
// Annotate the CommonJS export names for ESM import in node:
|
|
222
367
|
0 && (module.exports = {
|
|
223
368
|
SIEEmbedding,
|
|
224
|
-
|
|
369
|
+
SIENodePostprocessor,
|
|
370
|
+
SIESparseEmbeddingFunction,
|
|
371
|
+
createSIEExtractorTool
|
|
225
372
|
});
|
|
226
373
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * SIE embeddings integration for LlamaIndex.TS\n *\n * Provides embedding generation using SIE's encode endpoint:\n * - SIEEmbedding: Dense embeddings implementing BaseEmbedding\n * - SIESparseEmbeddingFunction: Sparse embeddings for hybrid search\n *\n * @example\n * ```typescript\n * import { Settings } from \"llamaindex\";\n * import { SIEEmbedding } from \"@superlinked/sie-llamaindex\";\n *\n * // Set as default embedding model\n * Settings.embedModel = new SIEEmbedding({\n * baseUrl: \"http://localhost:8080\",\n * modelName: \"BAAI/bge-m3\",\n * });\n * ```\n */\n\nimport {\n type DType,\n type EncodeOptions,\n type EncodeResult,\n SIEClient,\n type SIEClientOptions,\n toNumberArray,\n} from \"@superlinked/sie-sdk\";\nimport { BaseEmbedding } from \"llamaindex\";\n\n/**\n * Configuration options for SIEEmbedding.\n */\nexport interface SIEEmbeddingOptions {\n /**\n * URL of the SIE server.\n * @default \"http://localhost:8080\"\n */\n baseUrl?: string;\n\n /**\n * Model name/ID to use for encoding.\n * @default \"BAAI/bge-m3\"\n */\n modelName?: string;\n\n /**\n * Optional pre-configured SIEClient instance.\n */\n client?: SIEClient;\n\n /**\n * Optional instruction prefix for embedding (model-dependent).\n */\n instruction?: string;\n\n /**\n * Output dtype: \"float32\" (default), \"float16\", \"int8\", \"binary\".\n */\n outputDtype?: DType;\n\n /**\n * Target GPU type for routing (e.g., \"l4\", \"a100-80gb\").\n */\n gpu?: string;\n\n /**\n * Request timeout in milliseconds.\n * @default 180000 (3 minutes)\n */\n timeout?: number;\n\n /**\n * Batch size for embedding multiple texts.\n * @default 10\n */\n embedBatchSize?: number;\n}\n\n/**\n * LlamaIndex BaseEmbedding implementation using SIE.\n *\n * Wraps SIEClient.encode() to implement the LlamaIndex BaseEmbedding interface.\n *\n * @example\n * ```typescript\n * import { Settings, VectorStoreIndex, Document } from \"llamaindex\";\n * import { SIEEmbedding } from \"@superlinked/sie-llamaindex\";\n *\n * // Set as default embedding model\n * Settings.embedModel = new SIEEmbedding({\n * baseUrl: \"http://localhost:8080\",\n * modelName: \"BAAI/bge-m3\",\n * });\n *\n * // Create index with documents\n * const index = await VectorStoreIndex.fromDocuments([\n * new Document({ text: \"Hello world\" }),\n * ]);\n *\n * // With GPU routing for multi-GPU clusters\n * const embedModel = new SIEEmbedding({\n * baseUrl: \"https://cluster.example.com\",\n * modelName: \"BAAI/bge-m3\",\n * gpu: \"a100-80gb\",\n * });\n * ```\n */\nexport class SIEEmbedding extends BaseEmbedding {\n readonly modelName: string;\n private readonly instruction?: string;\n private readonly outputDtype?: DType;\n private _client: SIEClient | undefined;\n private readonly baseUrl: string;\n private readonly clientOptions: SIEClientOptions;\n\n /**\n * Get embeddings for multiple text strings (documents).\n * This is a property (arrow function) to match BaseEmbedding interface.\n */\n override getTextEmbeddings = async (texts: string[]): Promise<number[][]> => {\n if (texts.length === 0) {\n return [];\n }\n\n const items = texts.map((text) => ({ text }));\n const options: EncodeOptions = {\n outputTypes: [\"dense\"],\n instruction: this.instruction,\n outputDtype: this.outputDtype,\n isQuery: false,\n };\n\n const results = await this.client.encode(this.modelName, items, options);\n return (results as EncodeResult[]).map((result) => this.extractDense(result));\n };\n\n constructor(options: SIEEmbeddingOptions = {}) {\n super();\n\n const {\n baseUrl = \"http://localhost:8080\",\n modelName = \"BAAI/bge-m3\",\n client,\n instruction,\n outputDtype,\n gpu,\n timeout = 180_000,\n embedBatchSize = 10,\n } = options;\n\n this.baseUrl = baseUrl;\n this.modelName = modelName;\n this.instruction = instruction;\n this.outputDtype = outputDtype;\n this._client = client;\n this.embedBatchSize = embedBatchSize;\n\n this.clientOptions = {\n timeout,\n gpu,\n };\n }\n\n /**\n * Get or create the SIEClient.\n */\n private get client(): SIEClient {\n if (!this._client) {\n this._client = new SIEClient(this.baseUrl, this.clientOptions);\n }\n return this._client;\n }\n\n /**\n * Get embedding for a single text string (document).\n *\n * @param text - Text to embed.\n * @returns Embedding vector as array of numbers.\n */\n async getTextEmbedding(text: string): Promise<number[]> {\n const options: EncodeOptions = {\n outputTypes: [\"dense\"],\n instruction: this.instruction,\n outputDtype: this.outputDtype,\n isQuery: false,\n };\n\n const result = await this.client.encode(this.modelName, { text }, options);\n return this.extractDense(result as EncodeResult);\n }\n\n /**\n * Extract dense embedding from encode result.\n */\n private extractDense(result: EncodeResult): number[] {\n const dense = result.dense;\n if (!dense) {\n throw new Error(\"Encode result missing dense embedding\");\n }\n return toNumberArray(dense);\n }\n\n /**\n * Close the underlying client connection.\n */\n async close(): Promise<void> {\n if (this._client) {\n await this._client.close();\n }\n }\n}\n\n/**\n * Configuration options for SIESparseEmbeddingFunction.\n */\nexport interface SIESparseEmbeddingFunctionOptions {\n /**\n * URL of the SIE server.\n * @default \"http://localhost:8080\"\n */\n baseUrl?: string;\n\n /**\n * Model name/ID to use for encoding. Must support sparse output.\n * @default \"BAAI/bge-m3\"\n */\n modelName?: string;\n\n /**\n * Target GPU type for routing (e.g., \"l4\", \"a100-80gb\").\n */\n gpu?: string;\n\n /**\n * Request timeout in milliseconds.\n * @default 180000 (3 minutes)\n */\n timeout?: number;\n}\n\n/**\n * Sparse embedding function for LlamaIndex hybrid search.\n *\n * Compatible with LlamaIndex vector stores that support hybrid search,\n * such as QdrantVectorStore with enableHybrid: true.\n *\n * @example\n * ```typescript\n * import { QdrantVectorStore } from \"llamaindex\";\n * import { SIESparseEmbeddingFunction } from \"@superlinked/sie-llamaindex\";\n *\n * const sparseEmbedFn = new SIESparseEmbeddingFunction({\n * baseUrl: \"http://localhost:8080\",\n * modelName: \"BAAI/bge-m3\",\n * });\n *\n * const vectorStore = new QdrantVectorStore({\n * client: qdrantClient,\n * collectionName: \"hybrid_docs\",\n * enableHybrid: true,\n * sparseEmbeddingFunction: sparseEmbedFn,\n * });\n * ```\n */\nexport class SIESparseEmbeddingFunction {\n private readonly modelName: string;\n private _client: SIEClient | undefined;\n private readonly baseUrl: string;\n private readonly clientOptions: SIEClientOptions;\n\n constructor(options: SIESparseEmbeddingFunctionOptions = {}) {\n const {\n baseUrl = \"http://localhost:8080\",\n modelName = \"BAAI/bge-m3\",\n gpu,\n timeout = 180_000,\n } = options;\n\n this.baseUrl = baseUrl;\n this.modelName = modelName;\n this.clientOptions = {\n timeout,\n gpu,\n };\n }\n\n /**\n * Get or create the SIEClient.\n */\n private get client(): SIEClient {\n if (!this._client) {\n this._client = new SIEClient(this.baseUrl, this.clientOptions);\n }\n return this._client;\n }\n\n /**\n * Encode query texts to sparse vectors.\n *\n * @param texts - List of query texts to encode.\n * @returns Tuple of [indices_list, values_list].\n */\n async encodeQueries(texts: string[]): Promise<[number[][], number[][]]> {\n if (texts.length === 0) {\n return [[], []];\n }\n\n const items = texts.map((text) => ({ text }));\n const options: EncodeOptions = {\n outputTypes: [\"sparse\"],\n isQuery: true,\n };\n\n const results = await this.client.encode(this.modelName, items, options);\n\n const indicesList: number[][] = [];\n const valuesList: number[][] = [];\n\n for (const result of results as EncodeResult[]) {\n const sparse = this.extractSparse(result);\n indicesList.push(sparse.indices);\n valuesList.push(sparse.values);\n }\n\n return [indicesList, valuesList];\n }\n\n /**\n * Encode document texts to sparse vectors.\n *\n * @param texts - List of document texts to encode.\n * @returns Tuple of [indices_list, values_list].\n */\n async encodeDocuments(texts: string[]): Promise<[number[][], number[][]]> {\n if (texts.length === 0) {\n return [[], []];\n }\n\n const items = texts.map((text) => ({ text }));\n const options: EncodeOptions = {\n outputTypes: [\"sparse\"],\n isQuery: false,\n };\n\n const results = await this.client.encode(this.modelName, items, options);\n\n const indicesList: number[][] = [];\n const valuesList: number[][] = [];\n\n for (const result of results as EncodeResult[]) {\n const sparse = this.extractSparse(result);\n indicesList.push(sparse.indices);\n valuesList.push(sparse.values);\n }\n\n return [indicesList, valuesList];\n }\n\n /**\n * Extract sparse embedding from encode result.\n */\n private extractSparse(result: EncodeResult): { indices: number[]; values: number[] } {\n const sparse = result.sparse;\n if (!sparse) {\n return { indices: [], values: [] };\n }\n\n return {\n indices: toNumberArray(sparse.indices),\n values: toNumberArray(sparse.values),\n };\n }\n\n /**\n * Close the underlying client connection.\n */\n async close(): Promise<void> {\n if (this._client) {\n await this._client.close();\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBA,qBAOO;AACP,wBAA8B;AAgFvB,IAAM,eAAN,cAA2B,gCAAc;AAAA,EACrC;AAAA,EACQ;AAAA,EACA;AAAA,EACT;AAAA,EACS;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMR,oBAAoB,OAAO,UAAyC;AAC3E,QAAI,MAAM,WAAW,GAAG;AACtB,aAAO,CAAC;AAAA,IACV;AAEA,UAAM,QAAQ,MAAM,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE;AAC5C,UAAM,UAAyB;AAAA,MAC7B,aAAa,CAAC,OAAO;AAAA,MACrB,aAAa,KAAK;AAAA,MAClB,aAAa,KAAK;AAAA,MAClB,SAAS;AAAA,IACX;AAEA,UAAM,UAAU,MAAM,KAAK,OAAO,OAAO,KAAK,WAAW,OAAO,OAAO;AACvE,WAAQ,QAA2B,IAAI,CAAC,WAAW,KAAK,aAAa,MAAM,CAAC;AAAA,EAC9E;AAAA,EAEA,YAAY,UAA+B,CAAC,GAAG;AAC7C,UAAM;AAEN,UAAM;AAAA,MACJ,UAAU;AAAA,MACV,YAAY;AAAA,MACZ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,UAAU;AAAA,MACV,iBAAiB;AAAA,IACnB,IAAI;AAEJ,SAAK,UAAU;AACf,SAAK,YAAY;AACjB,SAAK,cAAc;AACnB,SAAK,cAAc;AACnB,SAAK,UAAU;AACf,SAAK,iBAAiB;AAEtB,SAAK,gBAAgB;AAAA,MACnB;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,IAAY,SAAoB;AAC9B,QAAI,CAAC,KAAK,SAAS;AACjB,WAAK,UAAU,IAAI,yBAAU,KAAK,SAAS,KAAK,aAAa;AAAA,IAC/D;AACA,W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AAA,IACnC;AAEA,WAAO;AAAA,MACL,aAAS,8BAAc,OAAO,OAAO;AAAA,MACrC,YAAQ,8BAAc,OAAO,MAAM;AAAA,IACrC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAuB;AAC3B,QAAI,KAAK,SAAS;AAChB,YAAM,KAAK,QAAQ,MAAM;AAAA,IAC3B;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/rerankers.ts","../src/extractors.ts"],"sourcesContent":["/**\n * SIE embeddings integration for LlamaIndex.TS\n *\n * Provides embedding generation using SIE's encode endpoint:\n * - SIEEmbedding: Dense embeddings implementing BaseEmbedding\n * - SIESparseEmbeddingFunction: Sparse embeddings for hybrid search\n * - SIENodePostprocessor: Cross-encoder reranking for query pipelines\n * - createSIEExtractorTool: Entity extraction tool for agents\n *\n * @example\n * ```typescript\n * import { Settings } from \"llamaindex\";\n * import { SIEEmbedding } from \"@superlinked/sie-llamaindex\";\n *\n * // Set as default embedding model\n * Settings.embedModel = new SIEEmbedding({\n * baseUrl: \"http://localhost:8080\",\n * modelName: \"BAAI/bge-m3\",\n * });\n * ```\n */\n\nimport {\n type DType,\n type EncodeOptions,\n type EncodeResult,\n SIEClient,\n type SIEClientOptions,\n denseEmbedding,\n sparseEmbedding,\n} from \"@superlinked/sie-sdk\";\nimport { BaseEmbedding } from \"llamaindex\";\n\n/**\n * Configuration options for SIEEmbedding.\n */\nexport interface SIEEmbeddingOptions {\n /**\n * URL of the SIE server.\n * @default \"http://localhost:8080\"\n */\n baseUrl?: string;\n\n /**\n * Model name/ID to use for encoding.\n * @default \"BAAI/bge-m3\"\n */\n modelName?: string;\n\n /**\n * Optional pre-configured SIEClient instance.\n */\n client?: SIEClient;\n\n /**\n * Optional instruction prefix for embedding (model-dependent).\n */\n instruction?: string;\n\n /**\n * Output dtype: \"float32\" (default), \"float16\", \"int8\", \"binary\".\n */\n outputDtype?: DType;\n\n /**\n * Target GPU type for routing (e.g., \"l4\", \"a100-80gb\").\n */\n gpu?: string;\n\n /**\n * Request timeout in milliseconds.\n * @default 180000 (3 minutes)\n */\n timeout?: number;\n\n /**\n * Batch size for embedding multiple texts.\n * @default 10\n */\n embedBatchSize?: number;\n}\n\n/**\n * LlamaIndex BaseEmbedding implementation using SIE.\n *\n * Wraps SIEClient.encode() to implement the LlamaIndex BaseEmbedding interface.\n *\n * @example\n * ```typescript\n * import { Settings, VectorStoreIndex, Document } from \"llamaindex\";\n * import { SIEEmbedding } from \"@superlinked/sie-llamaindex\";\n *\n * // Set as default embedding model\n * Settings.embedModel = new SIEEmbedding({\n * baseUrl: \"http://localhost:8080\",\n * modelName: \"BAAI/bge-m3\",\n * });\n *\n * // Create index with documents\n * const index = await VectorStoreIndex.fromDocuments([\n * new Document({ text: \"Hello world\" }),\n * ]);\n *\n * // With GPU routing for multi-GPU clusters\n * const embedModel = new SIEEmbedding({\n * baseUrl: \"https://cluster.example.com\",\n * modelName: \"BAAI/bge-m3\",\n * gpu: \"a100-80gb\",\n * });\n * ```\n */\nexport class SIEEmbedding extends BaseEmbedding {\n readonly modelName: string;\n private readonly instruction?: string;\n private readonly outputDtype?: DType;\n private _client: SIEClient | undefined;\n private readonly baseUrl: string;\n private readonly clientOptions: SIEClientOptions;\n\n /**\n * Get embeddings for multiple text strings (documents).\n * This is a property (arrow function) to match BaseEmbedding interface.\n */\n override getTextEmbeddings = async (texts: string[]): Promise<number[][]> => {\n if (texts.length === 0) {\n return [];\n }\n\n const items = texts.map((text) => ({ text }));\n const options: EncodeOptions = {\n outputTypes: [\"dense\"],\n instruction: this.instruction,\n outputDtype: this.outputDtype,\n isQuery: false,\n };\n\n const results = await this.client.encode(this.modelName, items, options);\n return (results as EncodeResult[]).map((result) => denseEmbedding(result));\n };\n\n constructor(options: SIEEmbeddingOptions = {}) {\n super();\n\n const {\n baseUrl = \"http://localhost:8080\",\n modelName = \"BAAI/bge-m3\",\n client,\n instruction,\n outputDtype,\n gpu,\n timeout = 180_000,\n embedBatchSize = 10,\n } = options;\n\n this.baseUrl = baseUrl;\n this.modelName = modelName;\n this.instruction = instruction;\n this.outputDtype = outputDtype;\n this._client = client;\n this.embedBatchSize = embedBatchSize;\n\n this.clientOptions = {\n timeout,\n gpu,\n };\n }\n\n /**\n * Get or create the SIEClient.\n */\n private get client(): SIEClient {\n if (!this._client) {\n this._client = new SIEClient(this.baseUrl, this.clientOptions);\n }\n return this._client;\n }\n\n /**\n * Get embedding for a single text string (document).\n *\n * @param text - Text to embed.\n * @returns Embedding vector as array of numbers.\n */\n async getTextEmbedding(text: string): Promise<number[]> {\n const options: EncodeOptions = {\n outputTypes: [\"dense\"],\n instruction: this.instruction,\n outputDtype: this.outputDtype,\n isQuery: false,\n };\n\n const result = await this.client.encode(this.modelName, { text }, options);\n return denseEmbedding(result as EncodeResult);\n }\n\n /**\n * Close the underlying client connection.\n */\n async close(): Promise<void> {\n if (this._client) {\n await this._client.close();\n }\n }\n}\n\n/**\n * Configuration options for SIESparseEmbeddingFunction.\n */\nexport interface SIESparseEmbeddingFunctionOptions {\n /**\n * URL of the SIE server.\n * @default \"http://localhost:8080\"\n */\n baseUrl?: string;\n\n /**\n * Model name/ID to use for encoding. Must support sparse output.\n * @default \"BAAI/bge-m3\"\n */\n modelName?: string;\n\n /**\n * Target GPU type for routing (e.g., \"l4\", \"a100-80gb\").\n */\n gpu?: string;\n\n /**\n * Request timeout in milliseconds.\n * @default 180000 (3 minutes)\n */\n timeout?: number;\n}\n\n/**\n * Sparse embedding function for LlamaIndex hybrid search.\n *\n * Compatible with LlamaIndex vector stores that support hybrid search,\n * such as QdrantVectorStore with enableHybrid: true.\n *\n * @example\n * ```typescript\n * import { QdrantVectorStore } from \"llamaindex\";\n * import { SIESparseEmbeddingFunction } from \"@superlinked/sie-llamaindex\";\n *\n * const sparseEmbedFn = new SIESparseEmbeddingFunction({\n * baseUrl: \"http://localhost:8080\",\n * modelName: \"BAAI/bge-m3\",\n * });\n *\n * const vectorStore = new QdrantVectorStore({\n * client: qdrantClient,\n * collectionName: \"hybrid_docs\",\n * enableHybrid: true,\n * sparseEmbeddingFunction: sparseEmbedFn,\n * });\n * ```\n */\nexport class SIESparseEmbeddingFunction {\n private readonly modelName: string;\n private _client: SIEClient | undefined;\n private readonly baseUrl: string;\n private readonly clientOptions: SIEClientOptions;\n\n constructor(options: SIESparseEmbeddingFunctionOptions = {}) {\n const {\n baseUrl = \"http://localhost:8080\",\n modelName = \"BAAI/bge-m3\",\n gpu,\n timeout = 180_000,\n } = options;\n\n this.baseUrl = baseUrl;\n this.modelName = modelName;\n this.clientOptions = {\n timeout,\n gpu,\n };\n }\n\n /**\n * Get or create the SIEClient.\n */\n private get client(): SIEClient {\n if (!this._client) {\n this._client = new SIEClient(this.baseUrl, this.clientOptions);\n }\n return this._client;\n }\n\n /**\n * Encode query texts to sparse vectors.\n *\n * @param texts - List of query texts to encode.\n * @returns Tuple of [indices_list, values_list].\n */\n async encodeQueries(texts: string[]): Promise<[number[][], number[][]]> {\n if (texts.length === 0) {\n return [[], []];\n }\n\n const items = texts.map((text) => ({ text }));\n const options: EncodeOptions = {\n outputTypes: [\"sparse\"],\n isQuery: true,\n };\n\n const results = await this.client.encode(this.modelName, items, options);\n\n const indicesList: number[][] = [];\n const valuesList: number[][] = [];\n\n for (const result of results as EncodeResult[]) {\n const sparse = sparseEmbedding(result);\n indicesList.push(sparse.indices);\n valuesList.push(sparse.values);\n }\n\n return [indicesList, valuesList];\n }\n\n /**\n * Encode document texts to sparse vectors.\n *\n * @param texts - List of document texts to encode.\n * @returns Tuple of [indices_list, values_list].\n */\n async encodeDocuments(texts: string[]): Promise<[number[][], number[][]]> {\n if (texts.length === 0) {\n return [[], []];\n }\n\n const items = texts.map((text) => ({ text }));\n const options: EncodeOptions = {\n outputTypes: [\"sparse\"],\n isQuery: false,\n };\n\n const results = await this.client.encode(this.modelName, items, options);\n\n const indicesList: number[][] = [];\n const valuesList: number[][] = [];\n\n for (const result of results as EncodeResult[]) {\n const sparse = sparseEmbedding(result);\n indicesList.push(sparse.indices);\n valuesList.push(sparse.values);\n }\n\n return [indicesList, valuesList];\n }\n\n /**\n * Close the underlying client connection.\n */\n async close(): Promise<void> {\n if (this._client) {\n await this._client.close();\n }\n }\n}\n\nexport { SIENodePostprocessor, type SIENodePostprocessorOptions } from \"./rerankers.js\";\nexport { createSIEExtractorTool, type SIEExtractorToolOptions } from \"./extractors.js\";\n","/**\n * SIE reranker integration for LlamaIndex.TS\n *\n * Provides node reranking using SIE's score endpoint:\n * - SIENodePostprocessor: Cross-encoder reranking implementing BaseNodePostprocessor\n *\n * @example\n * ```typescript\n * import { SIENodePostprocessor } from \"@superlinked/sie-llamaindex\";\n *\n * const reranker = new SIENodePostprocessor({\n * baseUrl: \"http://localhost:8080\",\n * modelName: \"jinaai/jina-reranker-v2-base-multilingual\",\n * topN: 3,\n * });\n *\n * const reranked = await reranker.postprocessNodes(nodes, \"search query\");\n * ```\n */\n\nimport { SIEClient, type SIEClientOptions } from \"@superlinked/sie-sdk\";\nimport { MetadataMode } from \"llamaindex\";\nimport type { BaseNodePostprocessor, MessageContent, NodeWithScore } from \"llamaindex\";\n\n/**\n * Configuration options for SIENodePostprocessor.\n */\nexport interface SIENodePostprocessorOptions {\n /**\n * URL of the SIE server.\n * @default \"http://localhost:8080\"\n */\n baseUrl?: string;\n\n /**\n * Reranker model name/ID.\n * @default \"jinaai/jina-reranker-v2-base-multilingual\"\n */\n modelName?: string;\n\n /**\n * Optional pre-configured SIEClient instance.\n * If provided, baseUrl and other connection options are ignored.\n */\n client?: SIEClient;\n\n /**\n * Number of top nodes to return. If undefined, returns all nodes.\n */\n topN?: number;\n\n /**\n * Target GPU type for routing (e.g., \"l4\", \"a100-80gb\").\n */\n gpu?: string;\n\n /**\n * Request timeout in milliseconds.\n * @default 180000 (3 minutes)\n */\n timeout?: number;\n}\n\n/**\n * Extract a plain query string from LlamaIndex's MessageContent type.\n *\n * MessageContent is `string | MessageContentDetail[]`. For reranking\n * we need a plain string.\n */\nfunction extractQueryString(query: MessageContent): string {\n if (typeof query === \"string\") {\n return query;\n }\n // MessageContentDetail[] — concatenate text parts\n return query\n .filter(\n (part): part is { type: \"text\"; text: string } => \"type\" in part && part.type === \"text\",\n )\n .map((part) => part.text)\n .join(\" \");\n}\n\n/**\n * LlamaIndex node postprocessor using SIE's reranking.\n *\n * Wraps SIEClient.score() to implement the BaseNodePostprocessor interface.\n *\n * @example\n * ```typescript\n * import { VectorStoreIndex } from \"llamaindex\";\n * import { SIENodePostprocessor } from \"@superlinked/sie-llamaindex\";\n *\n * const reranker = new SIENodePostprocessor({\n * modelName: \"jinaai/jina-reranker-v2-base-multilingual\",\n * topN: 3,\n * });\n *\n * const queryEngine = index.asQueryEngine({\n * nodePostprocessors: [reranker],\n * });\n *\n * const response = await queryEngine.query({ query: \"What is the topic?\" });\n * ```\n */\nexport class SIENodePostprocessor implements BaseNodePostprocessor {\n readonly modelName: string;\n private readonly topN?: number;\n private _client: SIEClient | undefined;\n private readonly _ownsClient: boolean;\n private readonly baseUrl: string;\n private readonly clientOptions: SIEClientOptions;\n\n constructor(options: SIENodePostprocessorOptions = {}) {\n const {\n baseUrl = \"http://localhost:8080\",\n modelName = \"jinaai/jina-reranker-v2-base-multilingual\",\n client,\n topN,\n gpu,\n timeout = 180_000,\n } = options;\n\n this.baseUrl = baseUrl;\n this.modelName = modelName;\n this.topN = topN;\n this._client = client;\n this._ownsClient = !client;\n\n this.clientOptions = {\n timeout,\n gpu,\n };\n }\n\n /**\n * Get or create the SIEClient.\n */\n private get client(): SIEClient {\n if (!this._client) {\n this._client = new SIEClient(this.baseUrl, this.clientOptions);\n }\n return this._client;\n }\n\n /**\n * Rerank nodes by relevance to query.\n *\n * @param nodes - Nodes with scores to rerank.\n * @param query - Optional query string or MessageContent.\n * @returns Reranked nodes with updated scores, sorted by relevance descending.\n */\n async postprocessNodes(nodes: NodeWithScore[], query?: MessageContent): Promise<NodeWithScore[]> {\n if (nodes.length === 0 || query === undefined) {\n return nodes;\n }\n\n const queryText = extractQueryString(query);\n if (!queryText) {\n return nodes;\n }\n\n const queryItem = { text: queryText };\n const docItems = nodes.map((n) => ({ text: n.node.getContent(MetadataMode.NONE) }));\n\n const result = await this.client.score(this.modelName, queryItem, docItems);\n\n // Map score entries back to NodeWithScore with updated scores.\n // ScoreResult.scores are already sorted by score descending.\n const reranked: NodeWithScore[] = [];\n for (const entry of result.scores) {\n const idx = Number.parseInt(entry.itemId, 10);\n const original = nodes[idx];\n if (original) {\n reranked.push({\n node: original.node,\n score: entry.score,\n });\n }\n }\n\n if (this.topN !== undefined) {\n return reranked.slice(0, this.topN);\n }\n return reranked;\n }\n\n /**\n * Close the underlying client connection.\n */\n async close(): Promise<void> {\n if (this._client && this._ownsClient) {\n await this._client.close();\n }\n }\n}\n","/**\n * SIE extraction tool for LlamaIndex.TS\n *\n * Provides extraction using SIE's extract endpoint:\n * - createSIEExtractorTool: Factory that creates a FunctionTool for extraction\n *\n * Returns entities, relations, classifications, and detected objects.\n *\n * @example\n * ```typescript\n * import { createSIEExtractorTool } from \"@superlinked/sie-llamaindex\";\n *\n * const extractor = createSIEExtractorTool({\n * modelName: \"urchade/gliner_multi-v2.1\",\n * labels: [\"person\", \"organization\", \"location\"],\n * });\n *\n * const result = await extractor.call({ text: \"John Smith works at Acme Corp\" });\n * const parsed = JSON.parse(result);\n * console.log(parsed.entities);\n * ```\n */\n\nimport {\n type ExtractOptions,\n type ExtractResult,\n SIEClient,\n type SIEClientOptions,\n} from \"@superlinked/sie-sdk\";\nimport { FunctionTool } from \"llamaindex\";\n\n/**\n * Configuration options for createSIEExtractorTool.\n */\nexport interface SIEExtractorToolOptions {\n /**\n * URL of the SIE server.\n * @default \"http://localhost:8080\"\n */\n baseUrl?: string;\n\n /**\n * Extraction model name/ID.\n * @default \"urchade/gliner_multi-v2.1\"\n */\n modelName?: string;\n\n /**\n * Labels to extract.\n * @default [\"person\", \"organization\", \"location\"]\n */\n labels?: string[];\n\n /**\n * Minimum confidence threshold (0-1).\n */\n threshold?: number;\n\n /**\n * Target GPU type for routing (e.g., \"l4\", \"a100-80gb\").\n */\n gpu?: string;\n\n /**\n * Request timeout in milliseconds.\n * @default 180000 (3 minutes)\n */\n timeout?: number;\n\n /**\n * Tool name for the agent.\n * @default \"sie_extract\"\n */\n name?: string;\n\n /**\n * Tool description for the agent.\n */\n description?: string;\n}\n\n/**\n * Internal class to hold SIE extractor state.\n */\nclass _SIEExtractor {\n private readonly baseUrl: string;\n private readonly modelName: string;\n private readonly labels: string[];\n private readonly threshold?: number;\n private readonly clientOptions: SIEClientOptions;\n private _client: SIEClient | undefined;\n\n constructor(options: SIEExtractorToolOptions) {\n this.baseUrl = options.baseUrl ?? \"http://localhost:8080\";\n this.modelName = options.modelName ?? \"urchade/gliner_multi-v2.1\";\n this.labels = options.labels ?? [\"person\", \"organization\", \"location\"];\n this.threshold = options.threshold;\n this.clientOptions = {\n timeout: options.timeout ?? 180_000,\n gpu: options.gpu,\n };\n }\n\n private get client(): SIEClient {\n if (!this._client) {\n this._client = new SIEClient(this.baseUrl, this.clientOptions);\n }\n return this._client;\n }\n\n async extract(text: string): Promise<string> {\n const extractOptions: ExtractOptions = {\n labels: this.labels,\n };\n if (this.threshold !== undefined) {\n extractOptions.threshold = this.threshold;\n }\n\n const result: ExtractResult = await this.client.extract(this.modelName, { text }, extractOptions);\n\n return JSON.stringify({\n entities: result.entities.map((e) => ({\n text: e.text,\n label: e.label,\n score: e.score,\n ...(e.start !== undefined && { start: e.start }),\n ...(e.end !== undefined && { end: e.end }),\n })),\n relations: result.relations.map((r) => ({\n head: r.head,\n tail: r.tail,\n relation: r.relation,\n score: r.score,\n })),\n classifications: result.classifications.map((c) => ({\n label: c.label,\n score: c.score,\n })),\n objects: result.objects.map((o) => ({\n label: o.label,\n score: o.score,\n bbox: o.bbox,\n })),\n });\n }\n}\n\n/**\n * Create a LlamaIndex FunctionTool for extraction.\n *\n * Creates a tool that wraps SIE's extract endpoint for use with\n * LlamaIndex agents and workflows. Returns JSON with entities,\n * relations, classifications, and detected objects.\n *\n * @example\n * ```typescript\n * import { OpenAI, ReActAgent } from \"llamaindex\";\n * import { createSIEExtractorTool } from \"@superlinked/sie-llamaindex\";\n *\n * const extractor = createSIEExtractorTool({\n * modelName: \"urchade/gliner_multi-v2.1\",\n * labels: [\"person\", \"organization\", \"location\"],\n * });\n *\n * const agent = new ReActAgent({\n * tools: [extractor],\n * llm: new OpenAI(),\n * });\n *\n * const response = await agent.chat({\n * message: \"Extract entities from: John works at Google in NYC\",\n * });\n * ```\n *\n * @param options - Configuration for the extractor tool.\n * @returns FunctionTool wrapping SIE extraction.\n */\nexport function createSIEExtractorTool(options: SIEExtractorToolOptions = {}) {\n const labels = options.labels ?? [\"person\", \"organization\", \"location\"];\n const name = options.name ?? \"sie_extract\";\n const description =\n options.description ??\n `Extract structured information from text. Finds entities of types: ${labels.join(\", \")}. Returns entities, relations, classifications, and detected objects.`;\n\n const extractor = new _SIEExtractor(options);\n\n async function extract(input: { text: string }): Promise<string> {\n return extractor.extract(input.text);\n }\n\n return FunctionTool.from(extract, {\n name,\n description,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBA,IAAAA,kBAQO;AACP,IAAAC,qBAA8B;;;ACX9B,qBAAiD;AACjD,wBAA6B;AAgD7B,SAAS,mBAAmB,OAA+B;AACzD,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO;AAAA,EACT;AAEA,SAAO,MACJ;AAAA,IACC,CAAC,SAAiD,UAAU,QAAQ,KAAK,SAAS;AAAA,EACpF,EACC,IAAI,CAAC,SAAS,KAAK,IAAI,EACvB,KAAK,GAAG;AACb;AAwBO,IAAM,uBAAN,MAA4D;AAAA,EACxD;AAAA,EACQ;AAAA,EACT;AAAA,EACS;AAAA,EACA;AAAA,EACA;AAAA,EAEjB,YAAY,UAAuC,CAAC,GAAG;AACrD,UAAM;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;AAAA,MACtB,SAAS;AAAA,IACX;AAEA,UAAM,UAAU,MAAM,KAAK,OAAO,OAAO,KAAK,WAAW,OAAO,OAAO;AAEvE,UAAM,cAA0B,CAAC;AACjC,UAAM,aAAyB,CAAC;AAEhC,eAAW,UAAU,SAA2B;AAC9C,YAAM,aAAS,iCAAgB,MAAM;AACrC,kBAAY,KAAK,OAAO,OAAO;AAC/B,iBAAW,KAAK,OAAO,MAAM;AAAA,IAC/B;AAEA,WAAO,CAAC,aAAa,UAAU;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAuB;AAC3B,QAAI,KAAK,SAAS;AAChB,YAAM,KAAK,QAAQ,MAAM;AAAA,IAC3B;AAAA,EACF;AACF;","names":["import_sie_sdk","import_llamaindex","import_sie_sdk","import_llamaindex"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,183 @@
|
|
|
1
1
|
import { SIEClient, DType } from '@superlinked/sie-sdk';
|
|
2
|
-
import
|
|
2
|
+
import * as llamaindex from 'llamaindex';
|
|
3
|
+
import { BaseNodePostprocessor, NodeWithScore, MessageContent, FunctionTool, BaseEmbedding } from 'llamaindex';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* SIE reranker integration for LlamaIndex.TS
|
|
7
|
+
*
|
|
8
|
+
* Provides node reranking using SIE's score endpoint:
|
|
9
|
+
* - SIENodePostprocessor: Cross-encoder reranking implementing BaseNodePostprocessor
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { SIENodePostprocessor } from "@superlinked/sie-llamaindex";
|
|
14
|
+
*
|
|
15
|
+
* const reranker = new SIENodePostprocessor({
|
|
16
|
+
* baseUrl: "http://localhost:8080",
|
|
17
|
+
* modelName: "jinaai/jina-reranker-v2-base-multilingual",
|
|
18
|
+
* topN: 3,
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* const reranked = await reranker.postprocessNodes(nodes, "search query");
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Configuration options for SIENodePostprocessor.
|
|
27
|
+
*/
|
|
28
|
+
interface SIENodePostprocessorOptions {
|
|
29
|
+
/**
|
|
30
|
+
* URL of the SIE server.
|
|
31
|
+
* @default "http://localhost:8080"
|
|
32
|
+
*/
|
|
33
|
+
baseUrl?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Reranker model name/ID.
|
|
36
|
+
* @default "jinaai/jina-reranker-v2-base-multilingual"
|
|
37
|
+
*/
|
|
38
|
+
modelName?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Optional pre-configured SIEClient instance.
|
|
41
|
+
* If provided, baseUrl and other connection options are ignored.
|
|
42
|
+
*/
|
|
43
|
+
client?: SIEClient;
|
|
44
|
+
/**
|
|
45
|
+
* Number of top nodes to return. If undefined, returns all nodes.
|
|
46
|
+
*/
|
|
47
|
+
topN?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Target GPU type for routing (e.g., "l4", "a100-80gb").
|
|
50
|
+
*/
|
|
51
|
+
gpu?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Request timeout in milliseconds.
|
|
54
|
+
* @default 180000 (3 minutes)
|
|
55
|
+
*/
|
|
56
|
+
timeout?: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* LlamaIndex node postprocessor using SIE's reranking.
|
|
60
|
+
*
|
|
61
|
+
* Wraps SIEClient.score() to implement the BaseNodePostprocessor interface.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* import { VectorStoreIndex } from "llamaindex";
|
|
66
|
+
* import { SIENodePostprocessor } from "@superlinked/sie-llamaindex";
|
|
67
|
+
*
|
|
68
|
+
* const reranker = new SIENodePostprocessor({
|
|
69
|
+
* modelName: "jinaai/jina-reranker-v2-base-multilingual",
|
|
70
|
+
* topN: 3,
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* const queryEngine = index.asQueryEngine({
|
|
74
|
+
* nodePostprocessors: [reranker],
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* const response = await queryEngine.query({ query: "What is the topic?" });
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
declare class SIENodePostprocessor implements BaseNodePostprocessor {
|
|
81
|
+
readonly modelName: string;
|
|
82
|
+
private readonly topN?;
|
|
83
|
+
private _client;
|
|
84
|
+
private readonly _ownsClient;
|
|
85
|
+
private readonly baseUrl;
|
|
86
|
+
private readonly clientOptions;
|
|
87
|
+
constructor(options?: SIENodePostprocessorOptions);
|
|
88
|
+
/**
|
|
89
|
+
* Get or create the SIEClient.
|
|
90
|
+
*/
|
|
91
|
+
private get client();
|
|
92
|
+
/**
|
|
93
|
+
* Rerank nodes by relevance to query.
|
|
94
|
+
*
|
|
95
|
+
* @param nodes - Nodes with scores to rerank.
|
|
96
|
+
* @param query - Optional query string or MessageContent.
|
|
97
|
+
* @returns Reranked nodes with updated scores, sorted by relevance descending.
|
|
98
|
+
*/
|
|
99
|
+
postprocessNodes(nodes: NodeWithScore[], query?: MessageContent): Promise<NodeWithScore[]>;
|
|
100
|
+
/**
|
|
101
|
+
* Close the underlying client connection.
|
|
102
|
+
*/
|
|
103
|
+
close(): Promise<void>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Configuration options for createSIEExtractorTool.
|
|
108
|
+
*/
|
|
109
|
+
interface SIEExtractorToolOptions {
|
|
110
|
+
/**
|
|
111
|
+
* URL of the SIE server.
|
|
112
|
+
* @default "http://localhost:8080"
|
|
113
|
+
*/
|
|
114
|
+
baseUrl?: string;
|
|
115
|
+
/**
|
|
116
|
+
* Extraction model name/ID.
|
|
117
|
+
* @default "urchade/gliner_multi-v2.1"
|
|
118
|
+
*/
|
|
119
|
+
modelName?: string;
|
|
120
|
+
/**
|
|
121
|
+
* Labels to extract.
|
|
122
|
+
* @default ["person", "organization", "location"]
|
|
123
|
+
*/
|
|
124
|
+
labels?: string[];
|
|
125
|
+
/**
|
|
126
|
+
* Minimum confidence threshold (0-1).
|
|
127
|
+
*/
|
|
128
|
+
threshold?: number;
|
|
129
|
+
/**
|
|
130
|
+
* Target GPU type for routing (e.g., "l4", "a100-80gb").
|
|
131
|
+
*/
|
|
132
|
+
gpu?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Request timeout in milliseconds.
|
|
135
|
+
* @default 180000 (3 minutes)
|
|
136
|
+
*/
|
|
137
|
+
timeout?: number;
|
|
138
|
+
/**
|
|
139
|
+
* Tool name for the agent.
|
|
140
|
+
* @default "sie_extract"
|
|
141
|
+
*/
|
|
142
|
+
name?: string;
|
|
143
|
+
/**
|
|
144
|
+
* Tool description for the agent.
|
|
145
|
+
*/
|
|
146
|
+
description?: string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Create a LlamaIndex FunctionTool for extraction.
|
|
150
|
+
*
|
|
151
|
+
* Creates a tool that wraps SIE's extract endpoint for use with
|
|
152
|
+
* LlamaIndex agents and workflows. Returns JSON with entities,
|
|
153
|
+
* relations, classifications, and detected objects.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* import { OpenAI, ReActAgent } from "llamaindex";
|
|
158
|
+
* import { createSIEExtractorTool } from "@superlinked/sie-llamaindex";
|
|
159
|
+
*
|
|
160
|
+
* const extractor = createSIEExtractorTool({
|
|
161
|
+
* modelName: "urchade/gliner_multi-v2.1",
|
|
162
|
+
* labels: ["person", "organization", "location"],
|
|
163
|
+
* });
|
|
164
|
+
*
|
|
165
|
+
* const agent = new ReActAgent({
|
|
166
|
+
* tools: [extractor],
|
|
167
|
+
* llm: new OpenAI(),
|
|
168
|
+
* });
|
|
169
|
+
*
|
|
170
|
+
* const response = await agent.chat({
|
|
171
|
+
* message: "Extract entities from: John works at Google in NYC",
|
|
172
|
+
* });
|
|
173
|
+
* ```
|
|
174
|
+
*
|
|
175
|
+
* @param options - Configuration for the extractor tool.
|
|
176
|
+
* @returns FunctionTool wrapping SIE extraction.
|
|
177
|
+
*/
|
|
178
|
+
declare function createSIEExtractorTool(options?: SIEExtractorToolOptions): FunctionTool<{
|
|
179
|
+
text: string;
|
|
180
|
+
}, llamaindex.JSONValue | Promise<llamaindex.JSONValue>>;
|
|
3
181
|
|
|
4
182
|
/**
|
|
5
183
|
* SIE embeddings integration for LlamaIndex.TS
|
|
@@ -7,6 +185,8 @@ import { BaseEmbedding } from 'llamaindex';
|
|
|
7
185
|
* Provides embedding generation using SIE's encode endpoint:
|
|
8
186
|
* - SIEEmbedding: Dense embeddings implementing BaseEmbedding
|
|
9
187
|
* - SIESparseEmbeddingFunction: Sparse embeddings for hybrid search
|
|
188
|
+
* - SIENodePostprocessor: Cross-encoder reranking for query pipelines
|
|
189
|
+
* - createSIEExtractorTool: Entity extraction tool for agents
|
|
10
190
|
*
|
|
11
191
|
* @example
|
|
12
192
|
* ```typescript
|
|
@@ -115,10 +295,6 @@ declare class SIEEmbedding extends BaseEmbedding {
|
|
|
115
295
|
* @returns Embedding vector as array of numbers.
|
|
116
296
|
*/
|
|
117
297
|
getTextEmbedding(text: string): Promise<number[]>;
|
|
118
|
-
/**
|
|
119
|
-
* Extract dense embedding from encode result.
|
|
120
|
-
*/
|
|
121
|
-
private extractDense;
|
|
122
298
|
/**
|
|
123
299
|
* Close the underlying client connection.
|
|
124
300
|
*/
|
|
@@ -196,14 +372,10 @@ declare class SIESparseEmbeddingFunction {
|
|
|
196
372
|
* @returns Tuple of [indices_list, values_list].
|
|
197
373
|
*/
|
|
198
374
|
encodeDocuments(texts: string[]): Promise<[number[][], number[][]]>;
|
|
199
|
-
/**
|
|
200
|
-
* Extract sparse embedding from encode result.
|
|
201
|
-
*/
|
|
202
|
-
private extractSparse;
|
|
203
375
|
/**
|
|
204
376
|
* Close the underlying client connection.
|
|
205
377
|
*/
|
|
206
378
|
close(): Promise<void>;
|
|
207
379
|
}
|
|
208
380
|
|
|
209
|
-
export { SIEEmbedding, type SIEEmbeddingOptions, SIESparseEmbeddingFunction, type SIESparseEmbeddingFunctionOptions };
|
|
381
|
+
export { SIEEmbedding, type SIEEmbeddingOptions, type SIEExtractorToolOptions, SIENodePostprocessor, type SIENodePostprocessorOptions, SIESparseEmbeddingFunction, type SIESparseEmbeddingFunctionOptions, createSIEExtractorTool };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,183 @@
|
|
|
1
1
|
import { SIEClient, DType } from '@superlinked/sie-sdk';
|
|
2
|
-
import
|
|
2
|
+
import * as llamaindex from 'llamaindex';
|
|
3
|
+
import { BaseNodePostprocessor, NodeWithScore, MessageContent, FunctionTool, BaseEmbedding } from 'llamaindex';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* SIE reranker integration for LlamaIndex.TS
|
|
7
|
+
*
|
|
8
|
+
* Provides node reranking using SIE's score endpoint:
|
|
9
|
+
* - SIENodePostprocessor: Cross-encoder reranking implementing BaseNodePostprocessor
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { SIENodePostprocessor } from "@superlinked/sie-llamaindex";
|
|
14
|
+
*
|
|
15
|
+
* const reranker = new SIENodePostprocessor({
|
|
16
|
+
* baseUrl: "http://localhost:8080",
|
|
17
|
+
* modelName: "jinaai/jina-reranker-v2-base-multilingual",
|
|
18
|
+
* topN: 3,
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* const reranked = await reranker.postprocessNodes(nodes, "search query");
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Configuration options for SIENodePostprocessor.
|
|
27
|
+
*/
|
|
28
|
+
interface SIENodePostprocessorOptions {
|
|
29
|
+
/**
|
|
30
|
+
* URL of the SIE server.
|
|
31
|
+
* @default "http://localhost:8080"
|
|
32
|
+
*/
|
|
33
|
+
baseUrl?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Reranker model name/ID.
|
|
36
|
+
* @default "jinaai/jina-reranker-v2-base-multilingual"
|
|
37
|
+
*/
|
|
38
|
+
modelName?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Optional pre-configured SIEClient instance.
|
|
41
|
+
* If provided, baseUrl and other connection options are ignored.
|
|
42
|
+
*/
|
|
43
|
+
client?: SIEClient;
|
|
44
|
+
/**
|
|
45
|
+
* Number of top nodes to return. If undefined, returns all nodes.
|
|
46
|
+
*/
|
|
47
|
+
topN?: number;
|
|
48
|
+
/**
|
|
49
|
+
* Target GPU type for routing (e.g., "l4", "a100-80gb").
|
|
50
|
+
*/
|
|
51
|
+
gpu?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Request timeout in milliseconds.
|
|
54
|
+
* @default 180000 (3 minutes)
|
|
55
|
+
*/
|
|
56
|
+
timeout?: number;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* LlamaIndex node postprocessor using SIE's reranking.
|
|
60
|
+
*
|
|
61
|
+
* Wraps SIEClient.score() to implement the BaseNodePostprocessor interface.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* import { VectorStoreIndex } from "llamaindex";
|
|
66
|
+
* import { SIENodePostprocessor } from "@superlinked/sie-llamaindex";
|
|
67
|
+
*
|
|
68
|
+
* const reranker = new SIENodePostprocessor({
|
|
69
|
+
* modelName: "jinaai/jina-reranker-v2-base-multilingual",
|
|
70
|
+
* topN: 3,
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* const queryEngine = index.asQueryEngine({
|
|
74
|
+
* nodePostprocessors: [reranker],
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* const response = await queryEngine.query({ query: "What is the topic?" });
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
declare class SIENodePostprocessor implements BaseNodePostprocessor {
|
|
81
|
+
readonly modelName: string;
|
|
82
|
+
private readonly topN?;
|
|
83
|
+
private _client;
|
|
84
|
+
private readonly _ownsClient;
|
|
85
|
+
private readonly baseUrl;
|
|
86
|
+
private readonly clientOptions;
|
|
87
|
+
constructor(options?: SIENodePostprocessorOptions);
|
|
88
|
+
/**
|
|
89
|
+
* Get or create the SIEClient.
|
|
90
|
+
*/
|
|
91
|
+
private get client();
|
|
92
|
+
/**
|
|
93
|
+
* Rerank nodes by relevance to query.
|
|
94
|
+
*
|
|
95
|
+
* @param nodes - Nodes with scores to rerank.
|
|
96
|
+
* @param query - Optional query string or MessageContent.
|
|
97
|
+
* @returns Reranked nodes with updated scores, sorted by relevance descending.
|
|
98
|
+
*/
|
|
99
|
+
postprocessNodes(nodes: NodeWithScore[], query?: MessageContent): Promise<NodeWithScore[]>;
|
|
100
|
+
/**
|
|
101
|
+
* Close the underlying client connection.
|
|
102
|
+
*/
|
|
103
|
+
close(): Promise<void>;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Configuration options for createSIEExtractorTool.
|
|
108
|
+
*/
|
|
109
|
+
interface SIEExtractorToolOptions {
|
|
110
|
+
/**
|
|
111
|
+
* URL of the SIE server.
|
|
112
|
+
* @default "http://localhost:8080"
|
|
113
|
+
*/
|
|
114
|
+
baseUrl?: string;
|
|
115
|
+
/**
|
|
116
|
+
* Extraction model name/ID.
|
|
117
|
+
* @default "urchade/gliner_multi-v2.1"
|
|
118
|
+
*/
|
|
119
|
+
modelName?: string;
|
|
120
|
+
/**
|
|
121
|
+
* Labels to extract.
|
|
122
|
+
* @default ["person", "organization", "location"]
|
|
123
|
+
*/
|
|
124
|
+
labels?: string[];
|
|
125
|
+
/**
|
|
126
|
+
* Minimum confidence threshold (0-1).
|
|
127
|
+
*/
|
|
128
|
+
threshold?: number;
|
|
129
|
+
/**
|
|
130
|
+
* Target GPU type for routing (e.g., "l4", "a100-80gb").
|
|
131
|
+
*/
|
|
132
|
+
gpu?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Request timeout in milliseconds.
|
|
135
|
+
* @default 180000 (3 minutes)
|
|
136
|
+
*/
|
|
137
|
+
timeout?: number;
|
|
138
|
+
/**
|
|
139
|
+
* Tool name for the agent.
|
|
140
|
+
* @default "sie_extract"
|
|
141
|
+
*/
|
|
142
|
+
name?: string;
|
|
143
|
+
/**
|
|
144
|
+
* Tool description for the agent.
|
|
145
|
+
*/
|
|
146
|
+
description?: string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Create a LlamaIndex FunctionTool for extraction.
|
|
150
|
+
*
|
|
151
|
+
* Creates a tool that wraps SIE's extract endpoint for use with
|
|
152
|
+
* LlamaIndex agents and workflows. Returns JSON with entities,
|
|
153
|
+
* relations, classifications, and detected objects.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* import { OpenAI, ReActAgent } from "llamaindex";
|
|
158
|
+
* import { createSIEExtractorTool } from "@superlinked/sie-llamaindex";
|
|
159
|
+
*
|
|
160
|
+
* const extractor = createSIEExtractorTool({
|
|
161
|
+
* modelName: "urchade/gliner_multi-v2.1",
|
|
162
|
+
* labels: ["person", "organization", "location"],
|
|
163
|
+
* });
|
|
164
|
+
*
|
|
165
|
+
* const agent = new ReActAgent({
|
|
166
|
+
* tools: [extractor],
|
|
167
|
+
* llm: new OpenAI(),
|
|
168
|
+
* });
|
|
169
|
+
*
|
|
170
|
+
* const response = await agent.chat({
|
|
171
|
+
* message: "Extract entities from: John works at Google in NYC",
|
|
172
|
+
* });
|
|
173
|
+
* ```
|
|
174
|
+
*
|
|
175
|
+
* @param options - Configuration for the extractor tool.
|
|
176
|
+
* @returns FunctionTool wrapping SIE extraction.
|
|
177
|
+
*/
|
|
178
|
+
declare function createSIEExtractorTool(options?: SIEExtractorToolOptions): FunctionTool<{
|
|
179
|
+
text: string;
|
|
180
|
+
}, llamaindex.JSONValue | Promise<llamaindex.JSONValue>>;
|
|
3
181
|
|
|
4
182
|
/**
|
|
5
183
|
* SIE embeddings integration for LlamaIndex.TS
|
|
@@ -7,6 +185,8 @@ import { BaseEmbedding } from 'llamaindex';
|
|
|
7
185
|
* Provides embedding generation using SIE's encode endpoint:
|
|
8
186
|
* - SIEEmbedding: Dense embeddings implementing BaseEmbedding
|
|
9
187
|
* - SIESparseEmbeddingFunction: Sparse embeddings for hybrid search
|
|
188
|
+
* - SIENodePostprocessor: Cross-encoder reranking for query pipelines
|
|
189
|
+
* - createSIEExtractorTool: Entity extraction tool for agents
|
|
10
190
|
*
|
|
11
191
|
* @example
|
|
12
192
|
* ```typescript
|
|
@@ -115,10 +295,6 @@ declare class SIEEmbedding extends BaseEmbedding {
|
|
|
115
295
|
* @returns Embedding vector as array of numbers.
|
|
116
296
|
*/
|
|
117
297
|
getTextEmbedding(text: string): Promise<number[]>;
|
|
118
|
-
/**
|
|
119
|
-
* Extract dense embedding from encode result.
|
|
120
|
-
*/
|
|
121
|
-
private extractDense;
|
|
122
298
|
/**
|
|
123
299
|
* Close the underlying client connection.
|
|
124
300
|
*/
|
|
@@ -196,14 +372,10 @@ declare class SIESparseEmbeddingFunction {
|
|
|
196
372
|
* @returns Tuple of [indices_list, values_list].
|
|
197
373
|
*/
|
|
198
374
|
encodeDocuments(texts: string[]): Promise<[number[][], number[][]]>;
|
|
199
|
-
/**
|
|
200
|
-
* Extract sparse embedding from encode result.
|
|
201
|
-
*/
|
|
202
|
-
private extractSparse;
|
|
203
375
|
/**
|
|
204
376
|
* Close the underlying client connection.
|
|
205
377
|
*/
|
|
206
378
|
close(): Promise<void>;
|
|
207
379
|
}
|
|
208
380
|
|
|
209
|
-
export { SIEEmbedding, type SIEEmbeddingOptions, SIESparseEmbeddingFunction, type SIESparseEmbeddingFunctionOptions };
|
|
381
|
+
export { SIEEmbedding, type SIEEmbeddingOptions, type SIEExtractorToolOptions, SIENodePostprocessor, type SIENodePostprocessorOptions, SIESparseEmbeddingFunction, type SIESparseEmbeddingFunctionOptions, createSIEExtractorTool };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,178 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import {
|
|
3
|
-
SIEClient,
|
|
4
|
-
|
|
3
|
+
SIEClient as SIEClient3,
|
|
4
|
+
denseEmbedding,
|
|
5
|
+
sparseEmbedding
|
|
5
6
|
} from "@superlinked/sie-sdk";
|
|
6
7
|
import { BaseEmbedding } from "llamaindex";
|
|
8
|
+
|
|
9
|
+
// src/rerankers.ts
|
|
10
|
+
import { SIEClient } from "@superlinked/sie-sdk";
|
|
11
|
+
import { MetadataMode } from "llamaindex";
|
|
12
|
+
function extractQueryString(query) {
|
|
13
|
+
if (typeof query === "string") {
|
|
14
|
+
return query;
|
|
15
|
+
}
|
|
16
|
+
return query.filter(
|
|
17
|
+
(part) => "type" in part && part.type === "text"
|
|
18
|
+
).map((part) => part.text).join(" ");
|
|
19
|
+
}
|
|
20
|
+
var SIENodePostprocessor = class {
|
|
21
|
+
modelName;
|
|
22
|
+
topN;
|
|
23
|
+
_client;
|
|
24
|
+
_ownsClient;
|
|
25
|
+
baseUrl;
|
|
26
|
+
clientOptions;
|
|
27
|
+
constructor(options = {}) {
|
|
28
|
+
const {
|
|
29
|
+
baseUrl = "http://localhost:8080",
|
|
30
|
+
modelName = "jinaai/jina-reranker-v2-base-multilingual",
|
|
31
|
+
client,
|
|
32
|
+
topN,
|
|
33
|
+
gpu,
|
|
34
|
+
timeout = 18e4
|
|
35
|
+
} = options;
|
|
36
|
+
this.baseUrl = baseUrl;
|
|
37
|
+
this.modelName = modelName;
|
|
38
|
+
this.topN = topN;
|
|
39
|
+
this._client = client;
|
|
40
|
+
this._ownsClient = !client;
|
|
41
|
+
this.clientOptions = {
|
|
42
|
+
timeout,
|
|
43
|
+
gpu
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Get or create the SIEClient.
|
|
48
|
+
*/
|
|
49
|
+
get client() {
|
|
50
|
+
if (!this._client) {
|
|
51
|
+
this._client = new SIEClient(this.baseUrl, this.clientOptions);
|
|
52
|
+
}
|
|
53
|
+
return this._client;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Rerank nodes by relevance to query.
|
|
57
|
+
*
|
|
58
|
+
* @param nodes - Nodes with scores to rerank.
|
|
59
|
+
* @param query - Optional query string or MessageContent.
|
|
60
|
+
* @returns Reranked nodes with updated scores, sorted by relevance descending.
|
|
61
|
+
*/
|
|
62
|
+
async postprocessNodes(nodes, query) {
|
|
63
|
+
if (nodes.length === 0 || query === void 0) {
|
|
64
|
+
return nodes;
|
|
65
|
+
}
|
|
66
|
+
const queryText = extractQueryString(query);
|
|
67
|
+
if (!queryText) {
|
|
68
|
+
return nodes;
|
|
69
|
+
}
|
|
70
|
+
const queryItem = { text: queryText };
|
|
71
|
+
const docItems = nodes.map((n) => ({ text: n.node.getContent(MetadataMode.NONE) }));
|
|
72
|
+
const result = await this.client.score(this.modelName, queryItem, docItems);
|
|
73
|
+
const reranked = [];
|
|
74
|
+
for (const entry of result.scores) {
|
|
75
|
+
const idx = Number.parseInt(entry.itemId, 10);
|
|
76
|
+
const original = nodes[idx];
|
|
77
|
+
if (original) {
|
|
78
|
+
reranked.push({
|
|
79
|
+
node: original.node,
|
|
80
|
+
score: entry.score
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (this.topN !== void 0) {
|
|
85
|
+
return reranked.slice(0, this.topN);
|
|
86
|
+
}
|
|
87
|
+
return reranked;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Close the underlying client connection.
|
|
91
|
+
*/
|
|
92
|
+
async close() {
|
|
93
|
+
if (this._client && this._ownsClient) {
|
|
94
|
+
await this._client.close();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// src/extractors.ts
|
|
100
|
+
import {
|
|
101
|
+
SIEClient as SIEClient2
|
|
102
|
+
} from "@superlinked/sie-sdk";
|
|
103
|
+
import { FunctionTool } from "llamaindex";
|
|
104
|
+
var _SIEExtractor = class {
|
|
105
|
+
baseUrl;
|
|
106
|
+
modelName;
|
|
107
|
+
labels;
|
|
108
|
+
threshold;
|
|
109
|
+
clientOptions;
|
|
110
|
+
_client;
|
|
111
|
+
constructor(options) {
|
|
112
|
+
this.baseUrl = options.baseUrl ?? "http://localhost:8080";
|
|
113
|
+
this.modelName = options.modelName ?? "urchade/gliner_multi-v2.1";
|
|
114
|
+
this.labels = options.labels ?? ["person", "organization", "location"];
|
|
115
|
+
this.threshold = options.threshold;
|
|
116
|
+
this.clientOptions = {
|
|
117
|
+
timeout: options.timeout ?? 18e4,
|
|
118
|
+
gpu: options.gpu
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
get client() {
|
|
122
|
+
if (!this._client) {
|
|
123
|
+
this._client = new SIEClient2(this.baseUrl, this.clientOptions);
|
|
124
|
+
}
|
|
125
|
+
return this._client;
|
|
126
|
+
}
|
|
127
|
+
async extract(text) {
|
|
128
|
+
const extractOptions = {
|
|
129
|
+
labels: this.labels
|
|
130
|
+
};
|
|
131
|
+
if (this.threshold !== void 0) {
|
|
132
|
+
extractOptions.threshold = this.threshold;
|
|
133
|
+
}
|
|
134
|
+
const result = await this.client.extract(this.modelName, { text }, extractOptions);
|
|
135
|
+
return JSON.stringify({
|
|
136
|
+
entities: result.entities.map((e) => ({
|
|
137
|
+
text: e.text,
|
|
138
|
+
label: e.label,
|
|
139
|
+
score: e.score,
|
|
140
|
+
...e.start !== void 0 && { start: e.start },
|
|
141
|
+
...e.end !== void 0 && { end: e.end }
|
|
142
|
+
})),
|
|
143
|
+
relations: result.relations.map((r) => ({
|
|
144
|
+
head: r.head,
|
|
145
|
+
tail: r.tail,
|
|
146
|
+
relation: r.relation,
|
|
147
|
+
score: r.score
|
|
148
|
+
})),
|
|
149
|
+
classifications: result.classifications.map((c) => ({
|
|
150
|
+
label: c.label,
|
|
151
|
+
score: c.score
|
|
152
|
+
})),
|
|
153
|
+
objects: result.objects.map((o) => ({
|
|
154
|
+
label: o.label,
|
|
155
|
+
score: o.score,
|
|
156
|
+
bbox: o.bbox
|
|
157
|
+
}))
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
function createSIEExtractorTool(options = {}) {
|
|
162
|
+
const labels = options.labels ?? ["person", "organization", "location"];
|
|
163
|
+
const name = options.name ?? "sie_extract";
|
|
164
|
+
const description = options.description ?? `Extract structured information from text. Finds entities of types: ${labels.join(", ")}. Returns entities, relations, classifications, and detected objects.`;
|
|
165
|
+
const extractor = new _SIEExtractor(options);
|
|
166
|
+
async function extract(input) {
|
|
167
|
+
return extractor.extract(input.text);
|
|
168
|
+
}
|
|
169
|
+
return FunctionTool.from(extract, {
|
|
170
|
+
name,
|
|
171
|
+
description
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// src/index.ts
|
|
7
176
|
var SIEEmbedding = class extends BaseEmbedding {
|
|
8
177
|
modelName;
|
|
9
178
|
instruction;
|
|
@@ -27,7 +196,7 @@ var SIEEmbedding = class extends BaseEmbedding {
|
|
|
27
196
|
isQuery: false
|
|
28
197
|
};
|
|
29
198
|
const results = await this.client.encode(this.modelName, items, options);
|
|
30
|
-
return results.map((result) =>
|
|
199
|
+
return results.map((result) => denseEmbedding(result));
|
|
31
200
|
};
|
|
32
201
|
constructor(options = {}) {
|
|
33
202
|
super();
|
|
@@ -57,7 +226,7 @@ var SIEEmbedding = class extends BaseEmbedding {
|
|
|
57
226
|
*/
|
|
58
227
|
get client() {
|
|
59
228
|
if (!this._client) {
|
|
60
|
-
this._client = new
|
|
229
|
+
this._client = new SIEClient3(this.baseUrl, this.clientOptions);
|
|
61
230
|
}
|
|
62
231
|
return this._client;
|
|
63
232
|
}
|
|
@@ -75,17 +244,7 @@ var SIEEmbedding = class extends BaseEmbedding {
|
|
|
75
244
|
isQuery: false
|
|
76
245
|
};
|
|
77
246
|
const result = await this.client.encode(this.modelName, { text }, options);
|
|
78
|
-
return
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Extract dense embedding from encode result.
|
|
82
|
-
*/
|
|
83
|
-
extractDense(result) {
|
|
84
|
-
const dense = result.dense;
|
|
85
|
-
if (!dense) {
|
|
86
|
-
throw new Error("Encode result missing dense embedding");
|
|
87
|
-
}
|
|
88
|
-
return toNumberArray(dense);
|
|
247
|
+
return denseEmbedding(result);
|
|
89
248
|
}
|
|
90
249
|
/**
|
|
91
250
|
* Close the underlying client connection.
|
|
@@ -120,7 +279,7 @@ var SIESparseEmbeddingFunction = class {
|
|
|
120
279
|
*/
|
|
121
280
|
get client() {
|
|
122
281
|
if (!this._client) {
|
|
123
|
-
this._client = new
|
|
282
|
+
this._client = new SIEClient3(this.baseUrl, this.clientOptions);
|
|
124
283
|
}
|
|
125
284
|
return this._client;
|
|
126
285
|
}
|
|
@@ -143,7 +302,7 @@ var SIESparseEmbeddingFunction = class {
|
|
|
143
302
|
const indicesList = [];
|
|
144
303
|
const valuesList = [];
|
|
145
304
|
for (const result of results) {
|
|
146
|
-
const sparse =
|
|
305
|
+
const sparse = sparseEmbedding(result);
|
|
147
306
|
indicesList.push(sparse.indices);
|
|
148
307
|
valuesList.push(sparse.values);
|
|
149
308
|
}
|
|
@@ -168,25 +327,12 @@ var SIESparseEmbeddingFunction = class {
|
|
|
168
327
|
const indicesList = [];
|
|
169
328
|
const valuesList = [];
|
|
170
329
|
for (const result of results) {
|
|
171
|
-
const sparse =
|
|
330
|
+
const sparse = sparseEmbedding(result);
|
|
172
331
|
indicesList.push(sparse.indices);
|
|
173
332
|
valuesList.push(sparse.values);
|
|
174
333
|
}
|
|
175
334
|
return [indicesList, valuesList];
|
|
176
335
|
}
|
|
177
|
-
/**
|
|
178
|
-
* Extract sparse embedding from encode result.
|
|
179
|
-
*/
|
|
180
|
-
extractSparse(result) {
|
|
181
|
-
const sparse = result.sparse;
|
|
182
|
-
if (!sparse) {
|
|
183
|
-
return { indices: [], values: [] };
|
|
184
|
-
}
|
|
185
|
-
return {
|
|
186
|
-
indices: toNumberArray(sparse.indices),
|
|
187
|
-
values: toNumberArray(sparse.values)
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
336
|
/**
|
|
191
337
|
* Close the underlying client connection.
|
|
192
338
|
*/
|
|
@@ -198,6 +344,8 @@ var SIESparseEmbeddingFunction = class {
|
|
|
198
344
|
};
|
|
199
345
|
export {
|
|
200
346
|
SIEEmbedding,
|
|
201
|
-
|
|
347
|
+
SIENodePostprocessor,
|
|
348
|
+
SIESparseEmbeddingFunction,
|
|
349
|
+
createSIEExtractorTool
|
|
202
350
|
};
|
|
203
351
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * SIE embeddings integration for LlamaIndex.TS\n *\n * Provides embedding generation using SIE's encode endpoint:\n * - SIEEmbedding: Dense embeddings implementing BaseEmbedding\n * - SIESparseEmbeddingFunction: Sparse embeddings for hybrid search\n *\n * @example\n * ```typescript\n * import { Settings } from \"llamaindex\";\n * import { SIEEmbedding } from \"@superlinked/sie-llamaindex\";\n *\n * // Set as default embedding model\n * Settings.embedModel = new SIEEmbedding({\n * baseUrl: \"http://localhost:8080\",\n * modelName: \"BAAI/bge-m3\",\n * });\n * ```\n */\n\nimport {\n type DType,\n type EncodeOptions,\n type EncodeResult,\n SIEClient,\n type SIEClientOptions,\n toNumberArray,\n} from \"@superlinked/sie-sdk\";\nimport { BaseEmbedding } from \"llamaindex\";\n\n/**\n * Configuration options for SIEEmbedding.\n */\nexport interface SIEEmbeddingOptions {\n /**\n * URL of the SIE server.\n * @default \"http://localhost:8080\"\n */\n baseUrl?: string;\n\n /**\n * Model name/ID to use for encoding.\n * @default \"BAAI/bge-m3\"\n */\n modelName?: string;\n\n /**\n * Optional pre-configured SIEClient instance.\n */\n client?: SIEClient;\n\n /**\n * Optional instruction prefix for embedding (model-dependent).\n */\n instruction?: string;\n\n /**\n * Output dtype: \"float32\" (default), \"float16\", \"int8\", \"binary\".\n */\n outputDtype?: DType;\n\n /**\n * Target GPU type for routing (e.g., \"l4\", \"a100-80gb\").\n */\n gpu?: string;\n\n /**\n * Request timeout in milliseconds.\n * @default 180000 (3 minutes)\n */\n timeout?: number;\n\n /**\n * Batch size for embedding multiple texts.\n * @default 10\n */\n embedBatchSize?: number;\n}\n\n/**\n * LlamaIndex BaseEmbedding implementation using SIE.\n *\n * Wraps SIEClient.encode() to implement the LlamaIndex BaseEmbedding interface.\n *\n * @example\n * ```typescript\n * import { Settings, VectorStoreIndex, Document } from \"llamaindex\";\n * import { SIEEmbedding } from \"@superlinked/sie-llamaindex\";\n *\n * // Set as default embedding model\n * Settings.embedModel = new SIEEmbedding({\n * baseUrl: \"http://localhost:8080\",\n * modelName: \"BAAI/bge-m3\",\n * });\n *\n * // Create index with documents\n * const index = await VectorStoreIndex.fromDocuments([\n * new Document({ text: \"Hello world\" }),\n * ]);\n *\n * // With GPU routing for multi-GPU clusters\n * const embedModel = new SIEEmbedding({\n * baseUrl: \"https://cluster.example.com\",\n * modelName: \"BAAI/bge-m3\",\n * gpu: \"a100-80gb\",\n * });\n * ```\n */\nexport class SIEEmbedding extends BaseEmbedding {\n readonly modelName: string;\n private readonly instruction?: string;\n private readonly outputDtype?: DType;\n private _client: SIEClient | undefined;\n private readonly baseUrl: string;\n private readonly clientOptions: SIEClientOptions;\n\n /**\n * Get embeddings for multiple text strings (documents).\n * This is a property (arrow function) to match BaseEmbedding interface.\n */\n override getTextEmbeddings = async (texts: string[]): Promise<number[][]> => {\n if (texts.length === 0) {\n return [];\n }\n\n const items = texts.map((text) => ({ text }));\n const options: EncodeOptions = {\n outputTypes: [\"dense\"],\n instruction: this.instruction,\n outputDtype: this.outputDtype,\n isQuery: false,\n };\n\n const results = await this.client.encode(this.modelName, items, options);\n return (results as EncodeResult[]).map((result) => this.extractDense(result));\n };\n\n constructor(options: SIEEmbeddingOptions = {}) {\n super();\n\n const {\n baseUrl = \"http://localhost:8080\",\n modelName = \"BAAI/bge-m3\",\n client,\n instruction,\n outputDtype,\n gpu,\n timeout = 180_000,\n embedBatchSize = 10,\n } = options;\n\n this.baseUrl = baseUrl;\n this.modelName = modelName;\n this.instruction = instruction;\n this.outputDtype = outputDtype;\n this._client = client;\n this.embedBatchSize = embedBatchSize;\n\n this.clientOptions = {\n timeout,\n gpu,\n };\n }\n\n /**\n * Get or create the SIEClient.\n */\n private get client(): SIEClient {\n if (!this._client) {\n this._client = new SIEClient(this.baseUrl, this.clientOptions);\n }\n return this._client;\n }\n\n /**\n * Get embedding for a single text string (document).\n *\n * @param text - Text to embed.\n * @returns Embedding vector as array of numbers.\n */\n async getTextEmbedding(text: string): Promise<number[]> {\n const options: EncodeOptions = {\n outputTypes: [\"dense\"],\n instruction: this.instruction,\n outputDtype: this.outputDtype,\n isQuery: false,\n };\n\n const result = await this.client.encode(this.modelName, { text }, options);\n return this.extractDense(result as EncodeResult);\n }\n\n /**\n * Extract dense embedding from encode result.\n */\n private extractDense(result: EncodeResult): number[] {\n const dense = result.dense;\n if (!dense) {\n throw new Error(\"Encode result missing dense embedding\");\n }\n return toNumberArray(dense);\n }\n\n /**\n * Close the underlying client connection.\n */\n async close(): Promise<void> {\n if (this._client) {\n await this._client.close();\n }\n }\n}\n\n/**\n * Configuration options for SIESparseEmbeddingFunction.\n */\nexport interface SIESparseEmbeddingFunctionOptions {\n /**\n * URL of the SIE server.\n * @default \"http://localhost:8080\"\n */\n baseUrl?: string;\n\n /**\n * Model name/ID to use for encoding. Must support sparse output.\n * @default \"BAAI/bge-m3\"\n */\n modelName?: string;\n\n /**\n * Target GPU type for routing (e.g., \"l4\", \"a100-80gb\").\n */\n gpu?: string;\n\n /**\n * Request timeout in milliseconds.\n * @default 180000 (3 minutes)\n */\n timeout?: number;\n}\n\n/**\n * Sparse embedding function for LlamaIndex hybrid search.\n *\n * Compatible with LlamaIndex vector stores that support hybrid search,\n * such as QdrantVectorStore with enableHybrid: true.\n *\n * @example\n * ```typescript\n * import { QdrantVectorStore } from \"llamaindex\";\n * import { SIESparseEmbeddingFunction } from \"@superlinked/sie-llamaindex\";\n *\n * const sparseEmbedFn = new SIESparseEmbeddingFunction({\n * baseUrl: \"http://localhost:8080\",\n * modelName: \"BAAI/bge-m3\",\n * });\n *\n * const vectorStore = new QdrantVectorStore({\n * client: qdrantClient,\n * collectionName: \"hybrid_docs\",\n * enableHybrid: true,\n * sparseEmbeddingFunction: sparseEmbedFn,\n * });\n * ```\n */\nexport class SIESparseEmbeddingFunction {\n private readonly modelName: string;\n private _client: SIEClient | undefined;\n private readonly baseUrl: string;\n private readonly clientOptions: SIEClientOptions;\n\n constructor(options: SIESparseEmbeddingFunctionOptions = {}) {\n const {\n baseUrl = \"http://localhost:8080\",\n modelName = \"BAAI/bge-m3\",\n gpu,\n timeout = 180_000,\n } = options;\n\n this.baseUrl = baseUrl;\n this.modelName = modelName;\n this.clientOptions = {\n timeout,\n gpu,\n };\n }\n\n /**\n * Get or create the SIEClient.\n */\n private get client(): SIEClient {\n if (!this._client) {\n this._client = new SIEClient(this.baseUrl, this.clientOptions);\n }\n return this._client;\n }\n\n /**\n * Encode query texts to sparse vectors.\n *\n * @param texts - List of query texts to encode.\n * @returns Tuple of [indices_list, values_list].\n */\n async encodeQueries(texts: string[]): Promise<[number[][], number[][]]> {\n if (texts.length === 0) {\n return [[], []];\n }\n\n const items = texts.map((text) => ({ text }));\n const options: EncodeOptions = {\n outputTypes: [\"sparse\"],\n isQuery: true,\n };\n\n const results = await this.client.encode(this.modelName, items, options);\n\n const indicesList: number[][] = [];\n const valuesList: number[][] = [];\n\n for (const result of results as EncodeResult[]) {\n const sparse = this.extractSparse(result);\n indicesList.push(sparse.indices);\n valuesList.push(sparse.values);\n }\n\n return [indicesList, valuesList];\n }\n\n /**\n * Encode document texts to sparse vectors.\n *\n * @param texts - List of document texts to encode.\n * @returns Tuple of [indices_list, values_list].\n */\n async encodeDocuments(texts: string[]): Promise<[number[][], number[][]]> {\n if (texts.length === 0) {\n return [[], []];\n }\n\n const items = texts.map((text) => ({ text }));\n const options: EncodeOptions = {\n outputTypes: [\"sparse\"],\n isQuery: false,\n };\n\n const results = await this.client.encode(this.modelName, items, options);\n\n const indicesList: number[][] = [];\n const valuesList: number[][] = [];\n\n for (const result of results as EncodeResult[]) {\n const sparse = this.extractSparse(result);\n indicesList.push(sparse.indices);\n valuesList.push(sparse.values);\n }\n\n return [indicesList, valuesList];\n }\n\n /**\n * Extract sparse embedding from encode result.\n */\n private extractSparse(result: EncodeResult): { indices: number[]; values: number[] } {\n const sparse = result.sparse;\n if (!sparse) {\n return { indices: [], values: [] };\n }\n\n return {\n indices: toNumberArray(sparse.indices),\n values: toNumberArray(sparse.values),\n };\n }\n\n /**\n * Close the underlying client connection.\n */\n async close(): Promise<void> {\n if (this._client) {\n await this._client.close();\n }\n }\n}\n"],"mappings":";AAoBA;AAAA,EAIE;AAAA,EAEA;AAAA,OACK;AACP,SAAS,qBAAqB;AAgFvB,IAAM,eAAN,cAA2B,cAAc;AAAA,EACrC;AAAA,EACQ;AAAA,EACA;AAAA,EACT;AAAA,EACS;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMR,oBAAoB,OAAO,UAAyC;AAC3E,QAAI,MAAM,WAAW,GAAG;AACtB,aAAO,CAAC;AAAA,IACV;AAEA,UAAM,QAAQ,MAAM,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE;AAC5C,UAAM,UAAyB;AAAA,MAC7B,aAAa,CAAC,OAAO;AAAA,MACrB,aAAa,KAAK;AAAA,MAClB,aAAa,KAAK;AAAA,MAClB,SAAS;AAAA,IACX;AAEA,UAAM,UAAU,MAAM,KAAK,OAAO,OAAO,KAAK,WAAW,OAAO,OAAO;AACvE,WAAQ,QAA2B,IAAI,CAAC,WAAW,KAAK,aAAa,MAAM,CAAC;AAAA,EAC9E;AAAA,EAEA,YAAY,UAA+B,CAAC,GAAG;AAC7C,UAAM;AAEN,UAAM;AAA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;AAEA,UAAM,UAAU,MAAM,KAAK,OAAO,OAAO,KAAK,WAAW,OAAO,OAAO;AAEvE,UAAM,cAA0B,CAAC;AACjC,UAAM,aAAyB,CAAC;AAEhC,eAAW,UAAU,SAA2B;AAC9C,YAAM,SAAS,KAAK,cAAc,MAAM;AACxC,kBAAY,KAAK,OAAO,OAAO;AAC/B,iBAAW,KAAK,OAAO,MAAM;AAAA,IAC/B;AAEA,WAAO,CAAC,aAAa,UAAU;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA,EAKQ,cAAc,QAA+D;AACnF,UAAM,SAAS,OAAO;AACtB,QAAI,CAAC,QAAQ;AACX,aAAO,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,EAAE;AAAA,IACnC;AAEA,WAAO;AAAA,MACL,SAAS,cAAc,OAAO,OAAO;AAAA,MACrC,QAAQ,cAAc,OAAO,MAAM;AAAA,IACrC;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAuB;AAC3B,QAAI,KAAK,SAAS;AAChB,YAAM,KAAK,QAAQ,MAAM;AAAA,IAC3B;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/rerankers.ts","../src/extractors.ts"],"sourcesContent":["/**\n * SIE embeddings integration for LlamaIndex.TS\n *\n * Provides embedding generation using SIE's encode endpoint:\n * - SIEEmbedding: Dense embeddings implementing BaseEmbedding\n * - SIESparseEmbeddingFunction: Sparse embeddings for hybrid search\n * - SIENodePostprocessor: Cross-encoder reranking for query pipelines\n * - createSIEExtractorTool: Entity extraction tool for agents\n *\n * @example\n * ```typescript\n * import { Settings } from \"llamaindex\";\n * import { SIEEmbedding } from \"@superlinked/sie-llamaindex\";\n *\n * // Set as default embedding model\n * Settings.embedModel = new SIEEmbedding({\n * baseUrl: \"http://localhost:8080\",\n * modelName: \"BAAI/bge-m3\",\n * });\n * ```\n */\n\nimport {\n type DType,\n type EncodeOptions,\n type EncodeResult,\n SIEClient,\n type SIEClientOptions,\n denseEmbedding,\n sparseEmbedding,\n} from \"@superlinked/sie-sdk\";\nimport { BaseEmbedding } from \"llamaindex\";\n\n/**\n * Configuration options for SIEEmbedding.\n */\nexport interface SIEEmbeddingOptions {\n /**\n * URL of the SIE server.\n * @default \"http://localhost:8080\"\n */\n baseUrl?: string;\n\n /**\n * Model name/ID to use for encoding.\n * @default \"BAAI/bge-m3\"\n */\n modelName?: string;\n\n /**\n * Optional pre-configured SIEClient instance.\n */\n client?: SIEClient;\n\n /**\n * Optional instruction prefix for embedding (model-dependent).\n */\n instruction?: string;\n\n /**\n * Output dtype: \"float32\" (default), \"float16\", \"int8\", \"binary\".\n */\n outputDtype?: DType;\n\n /**\n * Target GPU type for routing (e.g., \"l4\", \"a100-80gb\").\n */\n gpu?: string;\n\n /**\n * Request timeout in milliseconds.\n * @default 180000 (3 minutes)\n */\n timeout?: number;\n\n /**\n * Batch size for embedding multiple texts.\n * @default 10\n */\n embedBatchSize?: number;\n}\n\n/**\n * LlamaIndex BaseEmbedding implementation using SIE.\n *\n * Wraps SIEClient.encode() to implement the LlamaIndex BaseEmbedding interface.\n *\n * @example\n * ```typescript\n * import { Settings, VectorStoreIndex, Document } from \"llamaindex\";\n * import { SIEEmbedding } from \"@superlinked/sie-llamaindex\";\n *\n * // Set as default embedding model\n * Settings.embedModel = new SIEEmbedding({\n * baseUrl: \"http://localhost:8080\",\n * modelName: \"BAAI/bge-m3\",\n * });\n *\n * // Create index with documents\n * const index = await VectorStoreIndex.fromDocuments([\n * new Document({ text: \"Hello world\" }),\n * ]);\n *\n * // With GPU routing for multi-GPU clusters\n * const embedModel = new SIEEmbedding({\n * baseUrl: \"https://cluster.example.com\",\n * modelName: \"BAAI/bge-m3\",\n * gpu: \"a100-80gb\",\n * });\n * ```\n */\nexport class SIEEmbedding extends BaseEmbedding {\n readonly modelName: string;\n private readonly instruction?: string;\n private readonly outputDtype?: DType;\n private _client: SIEClient | undefined;\n private readonly baseUrl: string;\n private readonly clientOptions: SIEClientOptions;\n\n /**\n * Get embeddings for multiple text strings (documents).\n * This is a property (arrow function) to match BaseEmbedding interface.\n */\n override getTextEmbeddings = async (texts: string[]): Promise<number[][]> => {\n if (texts.length === 0) {\n return [];\n }\n\n const items = texts.map((text) => ({ text }));\n const options: EncodeOptions = {\n outputTypes: [\"dense\"],\n instruction: this.instruction,\n outputDtype: this.outputDtype,\n isQuery: false,\n };\n\n const results = await this.client.encode(this.modelName, items, options);\n return (results as EncodeResult[]).map((result) => denseEmbedding(result));\n };\n\n constructor(options: SIEEmbeddingOptions = {}) {\n super();\n\n const {\n baseUrl = \"http://localhost:8080\",\n modelName = \"BAAI/bge-m3\",\n client,\n instruction,\n outputDtype,\n gpu,\n timeout = 180_000,\n embedBatchSize = 10,\n } = options;\n\n this.baseUrl = baseUrl;\n this.modelName = modelName;\n this.instruction = instruction;\n this.outputDtype = outputDtype;\n this._client = client;\n this.embedBatchSize = embedBatchSize;\n\n this.clientOptions = {\n timeout,\n gpu,\n };\n }\n\n /**\n * Get or create the SIEClient.\n */\n private get client(): SIEClient {\n if (!this._client) {\n this._client = new SIEClient(this.baseUrl, this.clientOptions);\n }\n return this._client;\n }\n\n /**\n * Get embedding for a single text string (document).\n *\n * @param text - Text to embed.\n * @returns Embedding vector as array of numbers.\n */\n async getTextEmbedding(text: string): Promise<number[]> {\n const options: EncodeOptions = {\n outputTypes: [\"dense\"],\n instruction: this.instruction,\n outputDtype: this.outputDtype,\n isQuery: false,\n };\n\n const result = await this.client.encode(this.modelName, { text }, options);\n return denseEmbedding(result as EncodeResult);\n }\n\n /**\n * Close the underlying client connection.\n */\n async close(): Promise<void> {\n if (this._client) {\n await this._client.close();\n }\n }\n}\n\n/**\n * Configuration options for SIESparseEmbeddingFunction.\n */\nexport interface SIESparseEmbeddingFunctionOptions {\n /**\n * URL of the SIE server.\n * @default \"http://localhost:8080\"\n */\n baseUrl?: string;\n\n /**\n * Model name/ID to use for encoding. Must support sparse output.\n * @default \"BAAI/bge-m3\"\n */\n modelName?: string;\n\n /**\n * Target GPU type for routing (e.g., \"l4\", \"a100-80gb\").\n */\n gpu?: string;\n\n /**\n * Request timeout in milliseconds.\n * @default 180000 (3 minutes)\n */\n timeout?: number;\n}\n\n/**\n * Sparse embedding function for LlamaIndex hybrid search.\n *\n * Compatible with LlamaIndex vector stores that support hybrid search,\n * such as QdrantVectorStore with enableHybrid: true.\n *\n * @example\n * ```typescript\n * import { QdrantVectorStore } from \"llamaindex\";\n * import { SIESparseEmbeddingFunction } from \"@superlinked/sie-llamaindex\";\n *\n * const sparseEmbedFn = new SIESparseEmbeddingFunction({\n * baseUrl: \"http://localhost:8080\",\n * modelName: \"BAAI/bge-m3\",\n * });\n *\n * const vectorStore = new QdrantVectorStore({\n * client: qdrantClient,\n * collectionName: \"hybrid_docs\",\n * enableHybrid: true,\n * sparseEmbeddingFunction: sparseEmbedFn,\n * });\n * ```\n */\nexport class SIESparseEmbeddingFunction {\n private readonly modelName: string;\n private _client: SIEClient | undefined;\n private readonly baseUrl: string;\n private readonly clientOptions: SIEClientOptions;\n\n constructor(options: SIESparseEmbeddingFunctionOptions = {}) {\n const {\n baseUrl = \"http://localhost:8080\",\n modelName = \"BAAI/bge-m3\",\n gpu,\n timeout = 180_000,\n } = options;\n\n this.baseUrl = baseUrl;\n this.modelName = modelName;\n this.clientOptions = {\n timeout,\n gpu,\n };\n }\n\n /**\n * Get or create the SIEClient.\n */\n private get client(): SIEClient {\n if (!this._client) {\n this._client = new SIEClient(this.baseUrl, this.clientOptions);\n }\n return this._client;\n }\n\n /**\n * Encode query texts to sparse vectors.\n *\n * @param texts - List of query texts to encode.\n * @returns Tuple of [indices_list, values_list].\n */\n async encodeQueries(texts: string[]): Promise<[number[][], number[][]]> {\n if (texts.length === 0) {\n return [[], []];\n }\n\n const items = texts.map((text) => ({ text }));\n const options: EncodeOptions = {\n outputTypes: [\"sparse\"],\n isQuery: true,\n };\n\n const results = await this.client.encode(this.modelName, items, options);\n\n const indicesList: number[][] = [];\n const valuesList: number[][] = [];\n\n for (const result of results as EncodeResult[]) {\n const sparse = sparseEmbedding(result);\n indicesList.push(sparse.indices);\n valuesList.push(sparse.values);\n }\n\n return [indicesList, valuesList];\n }\n\n /**\n * Encode document texts to sparse vectors.\n *\n * @param texts - List of document texts to encode.\n * @returns Tuple of [indices_list, values_list].\n */\n async encodeDocuments(texts: string[]): Promise<[number[][], number[][]]> {\n if (texts.length === 0) {\n return [[], []];\n }\n\n const items = texts.map((text) => ({ text }));\n const options: EncodeOptions = {\n outputTypes: [\"sparse\"],\n isQuery: false,\n };\n\n const results = await this.client.encode(this.modelName, items, options);\n\n const indicesList: number[][] = [];\n const valuesList: number[][] = [];\n\n for (const result of results as EncodeResult[]) {\n const sparse = sparseEmbedding(result);\n indicesList.push(sparse.indices);\n valuesList.push(sparse.values);\n }\n\n return [indicesList, valuesList];\n }\n\n /**\n * Close the underlying client connection.\n */\n async close(): Promise<void> {\n if (this._client) {\n await this._client.close();\n }\n }\n}\n\nexport { SIENodePostprocessor, type SIENodePostprocessorOptions } from \"./rerankers.js\";\nexport { createSIEExtractorTool, type SIEExtractorToolOptions } from \"./extractors.js\";\n","/**\n * SIE reranker integration for LlamaIndex.TS\n *\n * Provides node reranking using SIE's score endpoint:\n * - SIENodePostprocessor: Cross-encoder reranking implementing BaseNodePostprocessor\n *\n * @example\n * ```typescript\n * import { SIENodePostprocessor } from \"@superlinked/sie-llamaindex\";\n *\n * const reranker = new SIENodePostprocessor({\n * baseUrl: \"http://localhost:8080\",\n * modelName: \"jinaai/jina-reranker-v2-base-multilingual\",\n * topN: 3,\n * });\n *\n * const reranked = await reranker.postprocessNodes(nodes, \"search query\");\n * ```\n */\n\nimport { SIEClient, type SIEClientOptions } from \"@superlinked/sie-sdk\";\nimport { MetadataMode } from \"llamaindex\";\nimport type { BaseNodePostprocessor, MessageContent, NodeWithScore } from \"llamaindex\";\n\n/**\n * Configuration options for SIENodePostprocessor.\n */\nexport interface SIENodePostprocessorOptions {\n /**\n * URL of the SIE server.\n * @default \"http://localhost:8080\"\n */\n baseUrl?: string;\n\n /**\n * Reranker model name/ID.\n * @default \"jinaai/jina-reranker-v2-base-multilingual\"\n */\n modelName?: string;\n\n /**\n * Optional pre-configured SIEClient instance.\n * If provided, baseUrl and other connection options are ignored.\n */\n client?: SIEClient;\n\n /**\n * Number of top nodes to return. If undefined, returns all nodes.\n */\n topN?: number;\n\n /**\n * Target GPU type for routing (e.g., \"l4\", \"a100-80gb\").\n */\n gpu?: string;\n\n /**\n * Request timeout in milliseconds.\n * @default 180000 (3 minutes)\n */\n timeout?: number;\n}\n\n/**\n * Extract a plain query string from LlamaIndex's MessageContent type.\n *\n * MessageContent is `string | MessageContentDetail[]`. For reranking\n * we need a plain string.\n */\nfunction extractQueryString(query: MessageContent): string {\n if (typeof query === \"string\") {\n return query;\n }\n // MessageContentDetail[] — concatenate text parts\n return query\n .filter(\n (part): part is { type: \"text\"; text: string } => \"type\" in part && part.type === \"text\",\n )\n .map((part) => part.text)\n .join(\" \");\n}\n\n/**\n * LlamaIndex node postprocessor using SIE's reranking.\n *\n * Wraps SIEClient.score() to implement the BaseNodePostprocessor interface.\n *\n * @example\n * ```typescript\n * import { VectorStoreIndex } from \"llamaindex\";\n * import { SIENodePostprocessor } from \"@superlinked/sie-llamaindex\";\n *\n * const reranker = new SIENodePostprocessor({\n * modelName: \"jinaai/jina-reranker-v2-base-multilingual\",\n * topN: 3,\n * });\n *\n * const queryEngine = index.asQueryEngine({\n * nodePostprocessors: [reranker],\n * });\n *\n * const response = await queryEngine.query({ query: \"What is the topic?\" });\n * ```\n */\nexport class SIENodePostprocessor implements BaseNodePostprocessor {\n readonly modelName: string;\n private readonly topN?: number;\n private _client: SIEClient | undefined;\n private readonly _ownsClient: boolean;\n private readonly baseUrl: string;\n private readonly clientOptions: SIEClientOptions;\n\n constructor(options: SIENodePostprocessorOptions = {}) {\n const {\n baseUrl = \"http://localhost:8080\",\n modelName = \"jinaai/jina-reranker-v2-base-multilingual\",\n client,\n topN,\n gpu,\n timeout = 180_000,\n } = options;\n\n this.baseUrl = baseUrl;\n this.modelName = modelName;\n this.topN = topN;\n this._client = client;\n this._ownsClient = !client;\n\n this.clientOptions = {\n timeout,\n gpu,\n };\n }\n\n /**\n * Get or create the SIEClient.\n */\n private get client(): SIEClient {\n if (!this._client) {\n this._client = new SIEClient(this.baseUrl, this.clientOptions);\n }\n return this._client;\n }\n\n /**\n * Rerank nodes by relevance to query.\n *\n * @param nodes - Nodes with scores to rerank.\n * @param query - Optional query string or MessageContent.\n * @returns Reranked nodes with updated scores, sorted by relevance descending.\n */\n async postprocessNodes(nodes: NodeWithScore[], query?: MessageContent): Promise<NodeWithScore[]> {\n if (nodes.length === 0 || query === undefined) {\n return nodes;\n }\n\n const queryText = extractQueryString(query);\n if (!queryText) {\n return nodes;\n }\n\n const queryItem = { text: queryText };\n const docItems = nodes.map((n) => ({ text: n.node.getContent(MetadataMode.NONE) }));\n\n const result = await this.client.score(this.modelName, queryItem, docItems);\n\n // Map score entries back to NodeWithScore with updated scores.\n // ScoreResult.scores are already sorted by score descending.\n const reranked: NodeWithScore[] = [];\n for (const entry of result.scores) {\n const idx = Number.parseInt(entry.itemId, 10);\n const original = nodes[idx];\n if (original) {\n reranked.push({\n node: original.node,\n score: entry.score,\n });\n }\n }\n\n if (this.topN !== undefined) {\n return reranked.slice(0, this.topN);\n }\n return reranked;\n }\n\n /**\n * Close the underlying client connection.\n */\n async close(): Promise<void> {\n if (this._client && this._ownsClient) {\n await this._client.close();\n }\n }\n}\n","/**\n * SIE extraction tool for LlamaIndex.TS\n *\n * Provides extraction using SIE's extract endpoint:\n * - createSIEExtractorTool: Factory that creates a FunctionTool for extraction\n *\n * Returns entities, relations, classifications, and detected objects.\n *\n * @example\n * ```typescript\n * import { createSIEExtractorTool } from \"@superlinked/sie-llamaindex\";\n *\n * const extractor = createSIEExtractorTool({\n * modelName: \"urchade/gliner_multi-v2.1\",\n * labels: [\"person\", \"organization\", \"location\"],\n * });\n *\n * const result = await extractor.call({ text: \"John Smith works at Acme Corp\" });\n * const parsed = JSON.parse(result);\n * console.log(parsed.entities);\n * ```\n */\n\nimport {\n type ExtractOptions,\n type ExtractResult,\n SIEClient,\n type SIEClientOptions,\n} from \"@superlinked/sie-sdk\";\nimport { FunctionTool } from \"llamaindex\";\n\n/**\n * Configuration options for createSIEExtractorTool.\n */\nexport interface SIEExtractorToolOptions {\n /**\n * URL of the SIE server.\n * @default \"http://localhost:8080\"\n */\n baseUrl?: string;\n\n /**\n * Extraction model name/ID.\n * @default \"urchade/gliner_multi-v2.1\"\n */\n modelName?: string;\n\n /**\n * Labels to extract.\n * @default [\"person\", \"organization\", \"location\"]\n */\n labels?: string[];\n\n /**\n * Minimum confidence threshold (0-1).\n */\n threshold?: number;\n\n /**\n * Target GPU type for routing (e.g., \"l4\", \"a100-80gb\").\n */\n gpu?: string;\n\n /**\n * Request timeout in milliseconds.\n * @default 180000 (3 minutes)\n */\n timeout?: number;\n\n /**\n * Tool name for the agent.\n * @default \"sie_extract\"\n */\n name?: string;\n\n /**\n * Tool description for the agent.\n */\n description?: string;\n}\n\n/**\n * Internal class to hold SIE extractor state.\n */\nclass _SIEExtractor {\n private readonly baseUrl: string;\n private readonly modelName: string;\n private readonly labels: string[];\n private readonly threshold?: number;\n private readonly clientOptions: SIEClientOptions;\n private _client: SIEClient | undefined;\n\n constructor(options: SIEExtractorToolOptions) {\n this.baseUrl = options.baseUrl ?? \"http://localhost:8080\";\n this.modelName = options.modelName ?? \"urchade/gliner_multi-v2.1\";\n this.labels = options.labels ?? [\"person\", \"organization\", \"location\"];\n this.threshold = options.threshold;\n this.clientOptions = {\n timeout: options.timeout ?? 180_000,\n gpu: options.gpu,\n };\n }\n\n private get client(): SIEClient {\n if (!this._client) {\n this._client = new SIEClient(this.baseUrl, this.clientOptions);\n }\n return this._client;\n }\n\n async extract(text: string): Promise<string> {\n const extractOptions: ExtractOptions = {\n labels: this.labels,\n };\n if (this.threshold !== undefined) {\n extractOptions.threshold = this.threshold;\n }\n\n const result: ExtractResult = await this.client.extract(this.modelName, { text }, extractOptions);\n\n return JSON.stringify({\n entities: result.entities.map((e) => ({\n text: e.text,\n label: e.label,\n score: e.score,\n ...(e.start !== undefined && { start: e.start }),\n ...(e.end !== undefined && { end: e.end }),\n })),\n relations: result.relations.map((r) => ({\n head: r.head,\n tail: r.tail,\n relation: r.relation,\n score: r.score,\n })),\n classifications: result.classifications.map((c) => ({\n label: c.label,\n score: c.score,\n })),\n objects: result.objects.map((o) => ({\n label: o.label,\n score: o.score,\n bbox: o.bbox,\n })),\n });\n }\n}\n\n/**\n * Create a LlamaIndex FunctionTool for extraction.\n *\n * Creates a tool that wraps SIE's extract endpoint for use with\n * LlamaIndex agents and workflows. Returns JSON with entities,\n * relations, classifications, and detected objects.\n *\n * @example\n * ```typescript\n * import { OpenAI, ReActAgent } from \"llamaindex\";\n * import { createSIEExtractorTool } from \"@superlinked/sie-llamaindex\";\n *\n * const extractor = createSIEExtractorTool({\n * modelName: \"urchade/gliner_multi-v2.1\",\n * labels: [\"person\", \"organization\", \"location\"],\n * });\n *\n * const agent = new ReActAgent({\n * tools: [extractor],\n * llm: new OpenAI(),\n * });\n *\n * const response = await agent.chat({\n * message: \"Extract entities from: John works at Google in NYC\",\n * });\n * ```\n *\n * @param options - Configuration for the extractor tool.\n * @returns FunctionTool wrapping SIE extraction.\n */\nexport function createSIEExtractorTool(options: SIEExtractorToolOptions = {}) {\n const labels = options.labels ?? [\"person\", \"organization\", \"location\"];\n const name = options.name ?? \"sie_extract\";\n const description =\n options.description ??\n `Extract structured information from text. Finds entities of types: ${labels.join(\", \")}. Returns entities, relations, classifications, and detected objects.`;\n\n const extractor = new _SIEExtractor(options);\n\n async function extract(input: { text: string }): Promise<string> {\n return extractor.extract(input.text);\n }\n\n return FunctionTool.from(extract, {\n name,\n description,\n });\n}\n"],"mappings":";AAsBA;AAAA,EAIE,aAAAA;AAAA,EAEA;AAAA,EACA;AAAA,OACK;AACP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W,UAAU,SAA2B;AAC9C,YAAM,SAAS,gBAAgB,MAAM;AACrC,kBAAY,KAAK,OAAO,OAAO;AAC/B,iBAAW,KAAK,OAAO,MAAM;AAAA,IAC/B;AAEA,WAAO,CAAC,aAAa,UAAU;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,gBAAgB,OAAoD;AACxE,QAAI,MAAM,WAAW,GAAG;AACtB,aAAO,CAAC,CAAC,GAAG,CAAC,CAAC;AAAA,IAChB;AAEA,UAAM,QAAQ,MAAM,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE;AAC5C,UAAM,UAAyB;AAAA,MAC7B,aAAa,CAAC,QAAQ;AAAA,MACtB,SAAS;AAAA,IACX;AAEA,UAAM,UAAU,MAAM,KAAK,OAAO,OAAO,KAAK,WAAW,OAAO,OAAO;AAEvE,UAAM,cAA0B,CAAC;AACjC,UAAM,aAAyB,CAAC;AAEhC,eAAW,UAAU,SAA2B;AAC9C,YAAM,SAAS,gBAAgB,MAAM;AACrC,kBAAY,KAAK,OAAO,OAAO;AAC/B,iBAAW,KAAK,OAAO,MAAM;AAAA,IAC/B;AAEA,WAAO,CAAC,aAAa,UAAU;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAuB;AAC3B,QAAI,KAAK,SAAS;AAChB,YAAM,KAAK,QAAQ,MAAM;AAAA,IAC3B;AAAA,EACF;AACF;","names":["SIEClient","SIEClient","SIEClient"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superlinked/sie-llamaindex",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "SIE embeddings integration for LlamaIndex.TS",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dist"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@superlinked/sie-sdk": "0.1.
|
|
20
|
+
"@superlinked/sie-sdk": "0.1.10"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"llamaindex": ">=0.6.0"
|