@m6d/cortex-cli 0.12.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -17,10 +17,17 @@ export type EmbeddingProviderConfig = {
|
|
|
17
17
|
/** Turns a batch of strings into their vectors, in the order given. */
|
|
18
18
|
export type EmbedFn = (values: string[]) => Promise<number[][]>;
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* The most inputs one embeddings request carries. Text Embeddings Inference
|
|
22
|
+
* refuses more than 32 by default; providers that allow larger batches just
|
|
23
|
+
* take more requests.
|
|
24
|
+
*/
|
|
25
|
+
export const EMBEDDING_MAX_BATCH_SIZE = 32;
|
|
26
|
+
|
|
20
27
|
export function createEmbedder(config: EmbeddingProviderConfig) {
|
|
21
28
|
const url = `${config.baseURL.replace(/\/+$/, "")}/embeddings`;
|
|
22
29
|
|
|
23
|
-
|
|
30
|
+
async function embedBatch(values: string[]) {
|
|
24
31
|
const response = await fetch(url, {
|
|
25
32
|
method: "POST",
|
|
26
33
|
headers: {
|
|
@@ -41,5 +48,15 @@ export function createEmbedder(config: EmbeddingProviderConfig) {
|
|
|
41
48
|
return [...body.data]
|
|
42
49
|
.sort((left, right) => left.index - right.index)
|
|
43
50
|
.map((entry) => entry.embedding);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return async function embed(values: string[]) {
|
|
54
|
+
const embeddings: number[][] = [];
|
|
55
|
+
for (let index = 0; index < values.length; index += EMBEDDING_MAX_BATCH_SIZE) {
|
|
56
|
+
embeddings.push(
|
|
57
|
+
...(await embedBatch(values.slice(index, index + EMBEDDING_MAX_BATCH_SIZE))),
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
return embeddings;
|
|
44
61
|
};
|
|
45
62
|
}
|
|
@@ -27,4 +27,4 @@ export type { Neo4jConfig, Neo4jClient, Neo4jRow } from "./clients/neo4j";
|
|
|
27
27
|
export { createNeo4jClient, Neo4jQueryError } from "./clients/neo4j";
|
|
28
28
|
|
|
29
29
|
export type { EmbedFn, EmbeddingProviderConfig } from "./clients/embed";
|
|
30
|
-
export { createEmbedder } from "./clients/embed";
|
|
30
|
+
export { createEmbedder, EMBEDDING_MAX_BATCH_SIZE } from "./clients/embed";
|
package/src/scaffold/files.ts
CHANGED
|
@@ -27,7 +27,7 @@ export type Database = "postgres" | "mssql";
|
|
|
27
27
|
// sync (scripts/sync-package-versions.ts) restamps it and files.test.ts holds
|
|
28
28
|
// them to that.
|
|
29
29
|
export const DEPENDENCIES = {
|
|
30
|
-
"@m6d/cortex-server": "~0.12.
|
|
30
|
+
"@m6d/cortex-server": "~0.12.1",
|
|
31
31
|
"@tanstack/ai": "^0.55.0",
|
|
32
32
|
"@tanstack/ai-openai": "^0.22.8",
|
|
33
33
|
hono: "^4.12.3",
|