@langchain/core 1.0.0-alpha.4 → 1.0.0-alpha.5
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/agents.d.ts.map +1 -1
- package/dist/caches/base.d.ts.map +1 -1
- package/dist/callbacks/base.d.ts.map +1 -1
- package/dist/language_models/chat_models.d.ts.map +1 -1
- package/dist/load/import_map.cjs +1 -1
- package/dist/load/import_map.js +1 -1
- package/dist/messages/ai.cjs +15 -10
- package/dist/messages/ai.cjs.map +1 -1
- package/dist/messages/ai.js +15 -10
- package/dist/messages/ai.js.map +1 -1
- package/dist/messages/base.cjs +8 -1
- package/dist/messages/base.cjs.map +1 -1
- package/dist/messages/base.js +8 -1
- package/dist/messages/base.js.map +1 -1
- package/dist/utils/testing/chat_models.cjs +245 -0
- package/dist/utils/testing/chat_models.cjs.map +1 -0
- package/dist/utils/testing/chat_models.d.cts +134 -0
- package/dist/utils/testing/chat_models.d.cts.map +1 -0
- package/dist/utils/testing/chat_models.d.ts +134 -0
- package/dist/utils/testing/chat_models.d.ts.map +1 -0
- package/dist/utils/testing/chat_models.js +243 -0
- package/dist/utils/testing/chat_models.js.map +1 -0
- package/dist/utils/testing/embeddings.cjs +90 -0
- package/dist/utils/testing/embeddings.cjs.map +1 -0
- package/dist/utils/testing/embeddings.d.cts +58 -0
- package/dist/utils/testing/embeddings.d.cts.map +1 -0
- package/dist/utils/testing/embeddings.d.ts +58 -0
- package/dist/utils/testing/embeddings.d.ts.map +1 -0
- package/dist/utils/testing/embeddings.js +89 -0
- package/dist/utils/testing/embeddings.js.map +1 -0
- package/dist/utils/testing/index.cjs +42 -655
- package/dist/utils/testing/index.cjs.map +1 -1
- package/dist/utils/testing/index.d.cts +11 -379
- package/dist/utils/testing/index.d.ts +11 -379
- package/dist/utils/testing/index.js +10 -623
- package/dist/utils/testing/index.js.map +1 -1
- package/dist/utils/testing/llms.cjs +59 -0
- package/dist/utils/testing/llms.cjs.map +1 -0
- package/dist/utils/testing/llms.d.cts +31 -0
- package/dist/utils/testing/llms.d.cts.map +1 -0
- package/dist/utils/testing/llms.d.ts +31 -0
- package/dist/utils/testing/llms.d.ts.map +1 -0
- package/dist/utils/testing/llms.js +58 -0
- package/dist/utils/testing/llms.js.map +1 -0
- package/dist/utils/testing/message_history.cjs +67 -0
- package/dist/utils/testing/message_history.cjs.map +1 -0
- package/dist/utils/testing/message_history.d.cts +31 -0
- package/dist/utils/testing/message_history.d.cts.map +1 -0
- package/dist/utils/testing/message_history.d.ts +31 -0
- package/dist/utils/testing/message_history.d.ts.map +1 -0
- package/dist/utils/testing/message_history.js +65 -0
- package/dist/utils/testing/message_history.js.map +1 -0
- package/dist/utils/testing/output_parsers.cjs +20 -0
- package/dist/utils/testing/output_parsers.cjs.map +1 -0
- package/dist/utils/testing/output_parsers.d.cts +16 -0
- package/dist/utils/testing/output_parsers.d.cts.map +1 -0
- package/dist/utils/testing/output_parsers.d.ts +16 -0
- package/dist/utils/testing/output_parsers.d.ts.map +1 -0
- package/dist/utils/testing/output_parsers.js +20 -0
- package/dist/utils/testing/output_parsers.js.map +1 -0
- package/dist/utils/testing/retrievers.cjs +19 -0
- package/dist/utils/testing/retrievers.cjs.map +1 -0
- package/dist/utils/testing/retrievers.d.cts +17 -0
- package/dist/utils/testing/retrievers.d.cts.map +1 -0
- package/dist/utils/testing/retrievers.d.ts +17 -0
- package/dist/utils/testing/retrievers.d.ts.map +1 -0
- package/dist/utils/testing/retrievers.js +19 -0
- package/dist/utils/testing/retrievers.js.map +1 -0
- package/dist/utils/testing/runnables.cjs +19 -0
- package/dist/utils/testing/runnables.cjs.map +1 -0
- package/dist/utils/testing/runnables.d.cts +15 -0
- package/dist/utils/testing/runnables.d.cts.map +1 -0
- package/dist/utils/testing/runnables.d.ts +15 -0
- package/dist/utils/testing/runnables.d.ts.map +1 -0
- package/dist/utils/testing/runnables.js +19 -0
- package/dist/utils/testing/runnables.js.map +1 -0
- package/dist/utils/testing/tools.cjs +21 -0
- package/dist/utils/testing/tools.cjs.map +1 -0
- package/dist/utils/testing/tools.d.cts +21 -0
- package/dist/utils/testing/tools.d.cts.map +1 -0
- package/dist/utils/testing/tools.d.ts +21 -0
- package/dist/utils/testing/tools.d.ts.map +1 -0
- package/dist/utils/testing/tools.js +21 -0
- package/dist/utils/testing/tools.js.map +1 -0
- package/dist/utils/testing/tracers.cjs +25 -0
- package/dist/utils/testing/tracers.cjs.map +1 -0
- package/dist/utils/testing/tracers.d.cts +15 -0
- package/dist/utils/testing/tracers.d.cts.map +1 -0
- package/dist/utils/testing/tracers.d.ts +15 -0
- package/dist/utils/testing/tracers.d.ts.map +1 -0
- package/dist/utils/testing/tracers.js +25 -0
- package/dist/utils/testing/tracers.js.map +1 -0
- package/dist/utils/testing/vectorstores.cjs +129 -0
- package/dist/utils/testing/vectorstores.cjs.map +1 -0
- package/dist/utils/testing/vectorstores.d.cts +101 -0
- package/dist/utils/testing/vectorstores.d.cts.map +1 -0
- package/dist/utils/testing/vectorstores.d.ts +101 -0
- package/dist/utils/testing/vectorstores.d.ts.map +1 -0
- package/dist/utils/testing/vectorstores.js +129 -0
- package/dist/utils/testing/vectorstores.js.map +1 -0
- package/package.json +1 -1
- package/dist/utils/testing/index.d.cts.map +0 -1
- package/dist/utils/testing/index.d.ts.map +0 -1
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const require_embeddings = require('../../embeddings.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/utils/testing/embeddings.ts
|
|
4
|
+
/**
|
|
5
|
+
* A class that provides synthetic embeddings by overriding the
|
|
6
|
+
* embedDocuments and embedQuery methods to generate embeddings based on
|
|
7
|
+
* the input documents. The embeddings are generated by converting each
|
|
8
|
+
* document into chunks, calculating a numerical value for each chunk, and
|
|
9
|
+
* returning an array of these values as the embedding.
|
|
10
|
+
*/
|
|
11
|
+
var SyntheticEmbeddings = class extends require_embeddings.Embeddings {
|
|
12
|
+
vectorSize;
|
|
13
|
+
constructor(params) {
|
|
14
|
+
super(params ?? {});
|
|
15
|
+
this.vectorSize = params?.vectorSize ?? 4;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generates synthetic embeddings for a list of documents.
|
|
19
|
+
* @param documents List of documents to generate embeddings for.
|
|
20
|
+
* @returns A promise that resolves with a list of synthetic embeddings for each document.
|
|
21
|
+
*/
|
|
22
|
+
async embedDocuments(documents) {
|
|
23
|
+
return Promise.all(documents.map((doc) => this.embedQuery(doc)));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Generates a synthetic embedding for a document. The document is
|
|
27
|
+
* converted into chunks, a numerical value is calculated for each chunk,
|
|
28
|
+
* and an array of these values is returned as the embedding.
|
|
29
|
+
* @param document The document to generate an embedding for.
|
|
30
|
+
* @returns A promise that resolves with a synthetic embedding for the document.
|
|
31
|
+
*/
|
|
32
|
+
async embedQuery(document) {
|
|
33
|
+
let doc = document;
|
|
34
|
+
doc = doc.toLowerCase().replaceAll(/[^a-z ]/g, "");
|
|
35
|
+
const padMod = doc.length % this.vectorSize;
|
|
36
|
+
const padGapSize = padMod === 0 ? 0 : this.vectorSize - padMod;
|
|
37
|
+
const padSize = doc.length + padGapSize;
|
|
38
|
+
doc = doc.padEnd(padSize, " ");
|
|
39
|
+
const chunkSize = doc.length / this.vectorSize;
|
|
40
|
+
const docChunk = [];
|
|
41
|
+
for (let co = 0; co < doc.length; co += chunkSize) docChunk.push(doc.slice(co, co + chunkSize));
|
|
42
|
+
const ret = docChunk.map((s) => {
|
|
43
|
+
let sum = 0;
|
|
44
|
+
for (let co = 0; co < s.length; co += 1) sum += s === " " ? 0 : s.charCodeAt(co);
|
|
45
|
+
const ret$1 = sum % 26 / 26;
|
|
46
|
+
return ret$1;
|
|
47
|
+
});
|
|
48
|
+
return ret;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* A class that provides fake embeddings by overriding the embedDocuments
|
|
53
|
+
* and embedQuery methods to return fixed values.
|
|
54
|
+
*/
|
|
55
|
+
var FakeEmbeddings = class extends require_embeddings.Embeddings {
|
|
56
|
+
constructor(params) {
|
|
57
|
+
super(params ?? {});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Generates fixed embeddings for a list of documents.
|
|
61
|
+
* @param documents List of documents to generate embeddings for.
|
|
62
|
+
* @returns A promise that resolves with a list of fixed embeddings for each document.
|
|
63
|
+
*/
|
|
64
|
+
embedDocuments(documents) {
|
|
65
|
+
return Promise.resolve(documents.map(() => [
|
|
66
|
+
.1,
|
|
67
|
+
.2,
|
|
68
|
+
.3,
|
|
69
|
+
.4
|
|
70
|
+
]));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Generates a fixed embedding for a query.
|
|
74
|
+
* @param _ The query to generate an embedding for.
|
|
75
|
+
* @returns A promise that resolves with a fixed embedding for the query.
|
|
76
|
+
*/
|
|
77
|
+
embedQuery(_) {
|
|
78
|
+
return Promise.resolve([
|
|
79
|
+
.1,
|
|
80
|
+
.2,
|
|
81
|
+
.3,
|
|
82
|
+
.4
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
exports.FakeEmbeddings = FakeEmbeddings;
|
|
89
|
+
exports.SyntheticEmbeddings = SyntheticEmbeddings;
|
|
90
|
+
//# sourceMappingURL=embeddings.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embeddings.cjs","names":["Embeddings","params?: SyntheticEmbeddingsParams","documents: string[]","document: string","ret: number[]","ret","params?: EmbeddingsParams","_: string"],"sources":["../../../src/utils/testing/embeddings.ts"],"sourcesContent":["import { Embeddings, EmbeddingsParams } from \"../../embeddings.js\";\n\n/**\n * An interface that defines additional parameters specific to the\n * SyntheticEmbeddings class.\n */\ninterface SyntheticEmbeddingsParams extends EmbeddingsParams {\n vectorSize: number;\n}\n\n/**\n * A class that provides synthetic embeddings by overriding the\n * embedDocuments and embedQuery methods to generate embeddings based on\n * the input documents. The embeddings are generated by converting each\n * document into chunks, calculating a numerical value for each chunk, and\n * returning an array of these values as the embedding.\n */\nexport class SyntheticEmbeddings\n extends Embeddings\n implements SyntheticEmbeddingsParams\n{\n vectorSize: number;\n\n constructor(params?: SyntheticEmbeddingsParams) {\n super(params ?? {});\n this.vectorSize = params?.vectorSize ?? 4;\n }\n\n /**\n * Generates synthetic embeddings for a list of documents.\n * @param documents List of documents to generate embeddings for.\n * @returns A promise that resolves with a list of synthetic embeddings for each document.\n */\n async embedDocuments(documents: string[]): Promise<number[][]> {\n return Promise.all(documents.map((doc) => this.embedQuery(doc)));\n }\n\n /**\n * Generates a synthetic embedding for a document. The document is\n * converted into chunks, a numerical value is calculated for each chunk,\n * and an array of these values is returned as the embedding.\n * @param document The document to generate an embedding for.\n * @returns A promise that resolves with a synthetic embedding for the document.\n */\n async embedQuery(document: string): Promise<number[]> {\n let doc = document;\n\n // Only use the letters (and space) from the document, and make them lower case\n doc = doc.toLowerCase().replaceAll(/[^a-z ]/g, \"\");\n\n // Pad the document to make sure it has a divisible number of chunks\n const padMod = doc.length % this.vectorSize;\n const padGapSize = padMod === 0 ? 0 : this.vectorSize - padMod;\n const padSize = doc.length + padGapSize;\n doc = doc.padEnd(padSize, \" \");\n\n // Break it into chunks\n const chunkSize = doc.length / this.vectorSize;\n const docChunk = [];\n for (let co = 0; co < doc.length; co += chunkSize) {\n docChunk.push(doc.slice(co, co + chunkSize));\n }\n\n // Turn each chunk into a number\n const ret: number[] = docChunk.map((s) => {\n let sum = 0;\n // Get a total value by adding the value of each character in the string\n for (let co = 0; co < s.length; co += 1) {\n sum += s === \" \" ? 0 : s.charCodeAt(co);\n }\n // Reduce this to a number between 0 and 25 inclusive\n // Then get the fractional number by dividing it by 26\n const ret = (sum % 26) / 26;\n return ret;\n });\n\n return ret;\n }\n}\n\n/**\n * A class that provides fake embeddings by overriding the embedDocuments\n * and embedQuery methods to return fixed values.\n */\nexport class FakeEmbeddings extends Embeddings {\n constructor(params?: EmbeddingsParams) {\n super(params ?? {});\n }\n\n /**\n * Generates fixed embeddings for a list of documents.\n * @param documents List of documents to generate embeddings for.\n * @returns A promise that resolves with a list of fixed embeddings for each document.\n */\n embedDocuments(documents: string[]): Promise<number[][]> {\n return Promise.resolve(documents.map(() => [0.1, 0.2, 0.3, 0.4]));\n }\n\n /**\n * Generates a fixed embedding for a query.\n * @param _ The query to generate an embedding for.\n * @returns A promise that resolves with a fixed embedding for the query.\n */\n embedQuery(_: string): Promise<number[]> {\n return Promise.resolve([0.1, 0.2, 0.3, 0.4]);\n }\n}\n"],"mappings":";;;;;;;;;;AAiBA,IAAa,sBAAb,cACUA,8BAEV;CACE;CAEA,YAAYC,QAAoC;EAC9C,MAAM,UAAU,CAAE,EAAC;EACnB,KAAK,aAAa,QAAQ,cAAc;CACzC;;;;;;CAOD,MAAM,eAAeC,WAA0C;AAC7D,SAAO,QAAQ,IAAI,UAAU,IAAI,CAAC,QAAQ,KAAK,WAAW,IAAI,CAAC,CAAC;CACjE;;;;;;;;CASD,MAAM,WAAWC,UAAqC;EACpD,IAAI,MAAM;EAGV,MAAM,IAAI,aAAa,CAAC,WAAW,YAAY,GAAG;EAGlD,MAAM,SAAS,IAAI,SAAS,KAAK;EACjC,MAAM,aAAa,WAAW,IAAI,IAAI,KAAK,aAAa;EACxD,MAAM,UAAU,IAAI,SAAS;EAC7B,MAAM,IAAI,OAAO,SAAS,IAAI;EAG9B,MAAM,YAAY,IAAI,SAAS,KAAK;EACpC,MAAM,WAAW,CAAE;AACnB,OAAK,IAAI,KAAK,GAAG,KAAK,IAAI,QAAQ,MAAM,WACtC,SAAS,KAAK,IAAI,MAAM,IAAI,KAAK,UAAU,CAAC;EAI9C,MAAMC,MAAgB,SAAS,IAAI,CAAC,MAAM;GACxC,IAAI,MAAM;AAEV,QAAK,IAAI,KAAK,GAAG,KAAK,EAAE,QAAQ,MAAM,GACpC,OAAO,MAAM,MAAM,IAAI,EAAE,WAAW,GAAG;GAIzC,MAAMC,QAAO,MAAM,KAAM;AACzB,UAAOA;EACR,EAAC;AAEF,SAAO;CACR;AACF;;;;;AAMD,IAAa,iBAAb,cAAoCL,8BAAW;CAC7C,YAAYM,QAA2B;EACrC,MAAM,UAAU,CAAE,EAAC;CACpB;;;;;;CAOD,eAAeJ,WAA0C;AACvD,SAAO,QAAQ,QAAQ,UAAU,IAAI,MAAM;GAAC;GAAK;GAAK;GAAK;EAAI,EAAC,CAAC;CAClE;;;;;;CAOD,WAAWK,GAA8B;AACvC,SAAO,QAAQ,QAAQ;GAAC;GAAK;GAAK;GAAK;EAAI,EAAC;CAC7C;AACF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Embeddings, EmbeddingsParams } from "../../embeddings.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/testing/embeddings.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An interface that defines additional parameters specific to the
|
|
7
|
+
* SyntheticEmbeddings class.
|
|
8
|
+
*/
|
|
9
|
+
interface SyntheticEmbeddingsParams extends EmbeddingsParams {
|
|
10
|
+
vectorSize: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A class that provides synthetic embeddings by overriding the
|
|
14
|
+
* embedDocuments and embedQuery methods to generate embeddings based on
|
|
15
|
+
* the input documents. The embeddings are generated by converting each
|
|
16
|
+
* document into chunks, calculating a numerical value for each chunk, and
|
|
17
|
+
* returning an array of these values as the embedding.
|
|
18
|
+
*/
|
|
19
|
+
declare class SyntheticEmbeddings extends Embeddings implements SyntheticEmbeddingsParams {
|
|
20
|
+
vectorSize: number;
|
|
21
|
+
constructor(params?: SyntheticEmbeddingsParams);
|
|
22
|
+
/**
|
|
23
|
+
* Generates synthetic embeddings for a list of documents.
|
|
24
|
+
* @param documents List of documents to generate embeddings for.
|
|
25
|
+
* @returns A promise that resolves with a list of synthetic embeddings for each document.
|
|
26
|
+
*/
|
|
27
|
+
embedDocuments(documents: string[]): Promise<number[][]>;
|
|
28
|
+
/**
|
|
29
|
+
* Generates a synthetic embedding for a document. The document is
|
|
30
|
+
* converted into chunks, a numerical value is calculated for each chunk,
|
|
31
|
+
* and an array of these values is returned as the embedding.
|
|
32
|
+
* @param document The document to generate an embedding for.
|
|
33
|
+
* @returns A promise that resolves with a synthetic embedding for the document.
|
|
34
|
+
*/
|
|
35
|
+
embedQuery(document: string): Promise<number[]>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A class that provides fake embeddings by overriding the embedDocuments
|
|
39
|
+
* and embedQuery methods to return fixed values.
|
|
40
|
+
*/
|
|
41
|
+
declare class FakeEmbeddings extends Embeddings {
|
|
42
|
+
constructor(params?: EmbeddingsParams);
|
|
43
|
+
/**
|
|
44
|
+
* Generates fixed embeddings for a list of documents.
|
|
45
|
+
* @param documents List of documents to generate embeddings for.
|
|
46
|
+
* @returns A promise that resolves with a list of fixed embeddings for each document.
|
|
47
|
+
*/
|
|
48
|
+
embedDocuments(documents: string[]): Promise<number[][]>;
|
|
49
|
+
/**
|
|
50
|
+
* Generates a fixed embedding for a query.
|
|
51
|
+
* @param _ The query to generate an embedding for.
|
|
52
|
+
* @returns A promise that resolves with a fixed embedding for the query.
|
|
53
|
+
*/
|
|
54
|
+
embedQuery(_: string): Promise<number[]>;
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { FakeEmbeddings, SyntheticEmbeddings };
|
|
58
|
+
//# sourceMappingURL=embeddings.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embeddings.d.cts","names":["Embeddings","EmbeddingsParams","SyntheticEmbeddingsParams","SyntheticEmbeddings","Promise","FakeEmbeddings"],"sources":["../../../src/utils/testing/embeddings.d.ts"],"sourcesContent":["import { Embeddings, EmbeddingsParams } from \"../../embeddings.js\";\n/**\n * An interface that defines additional parameters specific to the\n * SyntheticEmbeddings class.\n */\ninterface SyntheticEmbeddingsParams extends EmbeddingsParams {\n vectorSize: number;\n}\n/**\n * A class that provides synthetic embeddings by overriding the\n * embedDocuments and embedQuery methods to generate embeddings based on\n * the input documents. The embeddings are generated by converting each\n * document into chunks, calculating a numerical value for each chunk, and\n * returning an array of these values as the embedding.\n */\nexport declare class SyntheticEmbeddings extends Embeddings implements SyntheticEmbeddingsParams {\n vectorSize: number;\n constructor(params?: SyntheticEmbeddingsParams);\n /**\n * Generates synthetic embeddings for a list of documents.\n * @param documents List of documents to generate embeddings for.\n * @returns A promise that resolves with a list of synthetic embeddings for each document.\n */\n embedDocuments(documents: string[]): Promise<number[][]>;\n /**\n * Generates a synthetic embedding for a document. The document is\n * converted into chunks, a numerical value is calculated for each chunk,\n * and an array of these values is returned as the embedding.\n * @param document The document to generate an embedding for.\n * @returns A promise that resolves with a synthetic embedding for the document.\n */\n embedQuery(document: string): Promise<number[]>;\n}\n/**\n * A class that provides fake embeddings by overriding the embedDocuments\n * and embedQuery methods to return fixed values.\n */\nexport declare class FakeEmbeddings extends Embeddings {\n constructor(params?: EmbeddingsParams);\n /**\n * Generates fixed embeddings for a list of documents.\n * @param documents List of documents to generate embeddings for.\n * @returns A promise that resolves with a list of fixed embeddings for each document.\n */\n embedDocuments(documents: string[]): Promise<number[][]>;\n /**\n * Generates a fixed embedding for a query.\n * @param _ The query to generate an embedding for.\n * @returns A promise that resolves with a fixed embedding for the query.\n */\n embedQuery(_: string): Promise<number[]>;\n}\nexport {};\n"],"mappings":";;;;;;AAAmE;AAenE;UAVUE,yBAAAA,SAAkCD,gBAUJ,CAAA;EAAA,UAEfC,EAAAA,MAAAA;;;;;AAFuE;AAsBhG;;;AAOyCE,cA7BpBD,mBAAAA,SAA4BH,UAAAA,YAAsBE,yBA6B9BE,CAAAA;EAAO,UAMrBA,EAAAA,MAAAA;EAAO,WAbUJ,CAAAA,MAAAA,CAAAA,EApBnBE,yBAoBmBF;EAAU;;;;;uCAdbI;;;;;;;;gCAQPA;;;;;;cAMbC,cAAAA,SAAuBL,UAAAA;uBACnBC;;;;;;uCAMgBG;;;;;;yBAMdA"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Embeddings, EmbeddingsParams } from "../../embeddings.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/testing/embeddings.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An interface that defines additional parameters specific to the
|
|
7
|
+
* SyntheticEmbeddings class.
|
|
8
|
+
*/
|
|
9
|
+
interface SyntheticEmbeddingsParams extends EmbeddingsParams {
|
|
10
|
+
vectorSize: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A class that provides synthetic embeddings by overriding the
|
|
14
|
+
* embedDocuments and embedQuery methods to generate embeddings based on
|
|
15
|
+
* the input documents. The embeddings are generated by converting each
|
|
16
|
+
* document into chunks, calculating a numerical value for each chunk, and
|
|
17
|
+
* returning an array of these values as the embedding.
|
|
18
|
+
*/
|
|
19
|
+
declare class SyntheticEmbeddings extends Embeddings implements SyntheticEmbeddingsParams {
|
|
20
|
+
vectorSize: number;
|
|
21
|
+
constructor(params?: SyntheticEmbeddingsParams);
|
|
22
|
+
/**
|
|
23
|
+
* Generates synthetic embeddings for a list of documents.
|
|
24
|
+
* @param documents List of documents to generate embeddings for.
|
|
25
|
+
* @returns A promise that resolves with a list of synthetic embeddings for each document.
|
|
26
|
+
*/
|
|
27
|
+
embedDocuments(documents: string[]): Promise<number[][]>;
|
|
28
|
+
/**
|
|
29
|
+
* Generates a synthetic embedding for a document. The document is
|
|
30
|
+
* converted into chunks, a numerical value is calculated for each chunk,
|
|
31
|
+
* and an array of these values is returned as the embedding.
|
|
32
|
+
* @param document The document to generate an embedding for.
|
|
33
|
+
* @returns A promise that resolves with a synthetic embedding for the document.
|
|
34
|
+
*/
|
|
35
|
+
embedQuery(document: string): Promise<number[]>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A class that provides fake embeddings by overriding the embedDocuments
|
|
39
|
+
* and embedQuery methods to return fixed values.
|
|
40
|
+
*/
|
|
41
|
+
declare class FakeEmbeddings extends Embeddings {
|
|
42
|
+
constructor(params?: EmbeddingsParams);
|
|
43
|
+
/**
|
|
44
|
+
* Generates fixed embeddings for a list of documents.
|
|
45
|
+
* @param documents List of documents to generate embeddings for.
|
|
46
|
+
* @returns A promise that resolves with a list of fixed embeddings for each document.
|
|
47
|
+
*/
|
|
48
|
+
embedDocuments(documents: string[]): Promise<number[][]>;
|
|
49
|
+
/**
|
|
50
|
+
* Generates a fixed embedding for a query.
|
|
51
|
+
* @param _ The query to generate an embedding for.
|
|
52
|
+
* @returns A promise that resolves with a fixed embedding for the query.
|
|
53
|
+
*/
|
|
54
|
+
embedQuery(_: string): Promise<number[]>;
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { FakeEmbeddings, SyntheticEmbeddings };
|
|
58
|
+
//# sourceMappingURL=embeddings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embeddings.d.ts","names":["Embeddings","EmbeddingsParams","SyntheticEmbeddingsParams","SyntheticEmbeddings","Promise","FakeEmbeddings"],"sources":["../../../src/utils/testing/embeddings.d.ts"],"sourcesContent":["import { Embeddings, EmbeddingsParams } from \"../../embeddings.js\";\n/**\n * An interface that defines additional parameters specific to the\n * SyntheticEmbeddings class.\n */\ninterface SyntheticEmbeddingsParams extends EmbeddingsParams {\n vectorSize: number;\n}\n/**\n * A class that provides synthetic embeddings by overriding the\n * embedDocuments and embedQuery methods to generate embeddings based on\n * the input documents. The embeddings are generated by converting each\n * document into chunks, calculating a numerical value for each chunk, and\n * returning an array of these values as the embedding.\n */\nexport declare class SyntheticEmbeddings extends Embeddings implements SyntheticEmbeddingsParams {\n vectorSize: number;\n constructor(params?: SyntheticEmbeddingsParams);\n /**\n * Generates synthetic embeddings for a list of documents.\n * @param documents List of documents to generate embeddings for.\n * @returns A promise that resolves with a list of synthetic embeddings for each document.\n */\n embedDocuments(documents: string[]): Promise<number[][]>;\n /**\n * Generates a synthetic embedding for a document. The document is\n * converted into chunks, a numerical value is calculated for each chunk,\n * and an array of these values is returned as the embedding.\n * @param document The document to generate an embedding for.\n * @returns A promise that resolves with a synthetic embedding for the document.\n */\n embedQuery(document: string): Promise<number[]>;\n}\n/**\n * A class that provides fake embeddings by overriding the embedDocuments\n * and embedQuery methods to return fixed values.\n */\nexport declare class FakeEmbeddings extends Embeddings {\n constructor(params?: EmbeddingsParams);\n /**\n * Generates fixed embeddings for a list of documents.\n * @param documents List of documents to generate embeddings for.\n * @returns A promise that resolves with a list of fixed embeddings for each document.\n */\n embedDocuments(documents: string[]): Promise<number[][]>;\n /**\n * Generates a fixed embedding for a query.\n * @param _ The query to generate an embedding for.\n * @returns A promise that resolves with a fixed embedding for the query.\n */\n embedQuery(_: string): Promise<number[]>;\n}\nexport {};\n"],"mappings":";;;;;;AAAmE;AAenE;UAVUE,yBAAAA,SAAkCD,gBAUJ,CAAA;EAAA,UAEfC,EAAAA,MAAAA;;;;;AAFuE;AAsBhG;;;AAOyCE,cA7BpBD,mBAAAA,SAA4BH,UAAAA,YAAsBE,yBA6B9BE,CAAAA;EAAO,UAMrBA,EAAAA,MAAAA;EAAO,WAbUJ,CAAAA,MAAAA,CAAAA,EApBnBE,yBAoBmBF;EAAU;;;;;uCAdbI;;;;;;;;gCAQPA;;;;;;cAMbC,cAAAA,SAAuBL,UAAAA;uBACnBC;;;;;;uCAMgBG;;;;;;yBAMdA"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Embeddings } from "../../embeddings.js";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/testing/embeddings.ts
|
|
4
|
+
/**
|
|
5
|
+
* A class that provides synthetic embeddings by overriding the
|
|
6
|
+
* embedDocuments and embedQuery methods to generate embeddings based on
|
|
7
|
+
* the input documents. The embeddings are generated by converting each
|
|
8
|
+
* document into chunks, calculating a numerical value for each chunk, and
|
|
9
|
+
* returning an array of these values as the embedding.
|
|
10
|
+
*/
|
|
11
|
+
var SyntheticEmbeddings = class extends Embeddings {
|
|
12
|
+
vectorSize;
|
|
13
|
+
constructor(params) {
|
|
14
|
+
super(params ?? {});
|
|
15
|
+
this.vectorSize = params?.vectorSize ?? 4;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generates synthetic embeddings for a list of documents.
|
|
19
|
+
* @param documents List of documents to generate embeddings for.
|
|
20
|
+
* @returns A promise that resolves with a list of synthetic embeddings for each document.
|
|
21
|
+
*/
|
|
22
|
+
async embedDocuments(documents) {
|
|
23
|
+
return Promise.all(documents.map((doc) => this.embedQuery(doc)));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Generates a synthetic embedding for a document. The document is
|
|
27
|
+
* converted into chunks, a numerical value is calculated for each chunk,
|
|
28
|
+
* and an array of these values is returned as the embedding.
|
|
29
|
+
* @param document The document to generate an embedding for.
|
|
30
|
+
* @returns A promise that resolves with a synthetic embedding for the document.
|
|
31
|
+
*/
|
|
32
|
+
async embedQuery(document) {
|
|
33
|
+
let doc = document;
|
|
34
|
+
doc = doc.toLowerCase().replaceAll(/[^a-z ]/g, "");
|
|
35
|
+
const padMod = doc.length % this.vectorSize;
|
|
36
|
+
const padGapSize = padMod === 0 ? 0 : this.vectorSize - padMod;
|
|
37
|
+
const padSize = doc.length + padGapSize;
|
|
38
|
+
doc = doc.padEnd(padSize, " ");
|
|
39
|
+
const chunkSize = doc.length / this.vectorSize;
|
|
40
|
+
const docChunk = [];
|
|
41
|
+
for (let co = 0; co < doc.length; co += chunkSize) docChunk.push(doc.slice(co, co + chunkSize));
|
|
42
|
+
const ret = docChunk.map((s) => {
|
|
43
|
+
let sum = 0;
|
|
44
|
+
for (let co = 0; co < s.length; co += 1) sum += s === " " ? 0 : s.charCodeAt(co);
|
|
45
|
+
const ret$1 = sum % 26 / 26;
|
|
46
|
+
return ret$1;
|
|
47
|
+
});
|
|
48
|
+
return ret;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* A class that provides fake embeddings by overriding the embedDocuments
|
|
53
|
+
* and embedQuery methods to return fixed values.
|
|
54
|
+
*/
|
|
55
|
+
var FakeEmbeddings = class extends Embeddings {
|
|
56
|
+
constructor(params) {
|
|
57
|
+
super(params ?? {});
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Generates fixed embeddings for a list of documents.
|
|
61
|
+
* @param documents List of documents to generate embeddings for.
|
|
62
|
+
* @returns A promise that resolves with a list of fixed embeddings for each document.
|
|
63
|
+
*/
|
|
64
|
+
embedDocuments(documents) {
|
|
65
|
+
return Promise.resolve(documents.map(() => [
|
|
66
|
+
.1,
|
|
67
|
+
.2,
|
|
68
|
+
.3,
|
|
69
|
+
.4
|
|
70
|
+
]));
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Generates a fixed embedding for a query.
|
|
74
|
+
* @param _ The query to generate an embedding for.
|
|
75
|
+
* @returns A promise that resolves with a fixed embedding for the query.
|
|
76
|
+
*/
|
|
77
|
+
embedQuery(_) {
|
|
78
|
+
return Promise.resolve([
|
|
79
|
+
.1,
|
|
80
|
+
.2,
|
|
81
|
+
.3,
|
|
82
|
+
.4
|
|
83
|
+
]);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
export { FakeEmbeddings, SyntheticEmbeddings };
|
|
89
|
+
//# sourceMappingURL=embeddings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embeddings.js","names":["params?: SyntheticEmbeddingsParams","documents: string[]","document: string","ret: number[]","ret","params?: EmbeddingsParams","_: string"],"sources":["../../../src/utils/testing/embeddings.ts"],"sourcesContent":["import { Embeddings, EmbeddingsParams } from \"../../embeddings.js\";\n\n/**\n * An interface that defines additional parameters specific to the\n * SyntheticEmbeddings class.\n */\ninterface SyntheticEmbeddingsParams extends EmbeddingsParams {\n vectorSize: number;\n}\n\n/**\n * A class that provides synthetic embeddings by overriding the\n * embedDocuments and embedQuery methods to generate embeddings based on\n * the input documents. The embeddings are generated by converting each\n * document into chunks, calculating a numerical value for each chunk, and\n * returning an array of these values as the embedding.\n */\nexport class SyntheticEmbeddings\n extends Embeddings\n implements SyntheticEmbeddingsParams\n{\n vectorSize: number;\n\n constructor(params?: SyntheticEmbeddingsParams) {\n super(params ?? {});\n this.vectorSize = params?.vectorSize ?? 4;\n }\n\n /**\n * Generates synthetic embeddings for a list of documents.\n * @param documents List of documents to generate embeddings for.\n * @returns A promise that resolves with a list of synthetic embeddings for each document.\n */\n async embedDocuments(documents: string[]): Promise<number[][]> {\n return Promise.all(documents.map((doc) => this.embedQuery(doc)));\n }\n\n /**\n * Generates a synthetic embedding for a document. The document is\n * converted into chunks, a numerical value is calculated for each chunk,\n * and an array of these values is returned as the embedding.\n * @param document The document to generate an embedding for.\n * @returns A promise that resolves with a synthetic embedding for the document.\n */\n async embedQuery(document: string): Promise<number[]> {\n let doc = document;\n\n // Only use the letters (and space) from the document, and make them lower case\n doc = doc.toLowerCase().replaceAll(/[^a-z ]/g, \"\");\n\n // Pad the document to make sure it has a divisible number of chunks\n const padMod = doc.length % this.vectorSize;\n const padGapSize = padMod === 0 ? 0 : this.vectorSize - padMod;\n const padSize = doc.length + padGapSize;\n doc = doc.padEnd(padSize, \" \");\n\n // Break it into chunks\n const chunkSize = doc.length / this.vectorSize;\n const docChunk = [];\n for (let co = 0; co < doc.length; co += chunkSize) {\n docChunk.push(doc.slice(co, co + chunkSize));\n }\n\n // Turn each chunk into a number\n const ret: number[] = docChunk.map((s) => {\n let sum = 0;\n // Get a total value by adding the value of each character in the string\n for (let co = 0; co < s.length; co += 1) {\n sum += s === \" \" ? 0 : s.charCodeAt(co);\n }\n // Reduce this to a number between 0 and 25 inclusive\n // Then get the fractional number by dividing it by 26\n const ret = (sum % 26) / 26;\n return ret;\n });\n\n return ret;\n }\n}\n\n/**\n * A class that provides fake embeddings by overriding the embedDocuments\n * and embedQuery methods to return fixed values.\n */\nexport class FakeEmbeddings extends Embeddings {\n constructor(params?: EmbeddingsParams) {\n super(params ?? {});\n }\n\n /**\n * Generates fixed embeddings for a list of documents.\n * @param documents List of documents to generate embeddings for.\n * @returns A promise that resolves with a list of fixed embeddings for each document.\n */\n embedDocuments(documents: string[]): Promise<number[][]> {\n return Promise.resolve(documents.map(() => [0.1, 0.2, 0.3, 0.4]));\n }\n\n /**\n * Generates a fixed embedding for a query.\n * @param _ The query to generate an embedding for.\n * @returns A promise that resolves with a fixed embedding for the query.\n */\n embedQuery(_: string): Promise<number[]> {\n return Promise.resolve([0.1, 0.2, 0.3, 0.4]);\n }\n}\n"],"mappings":";;;;;;;;;;AAiBA,IAAa,sBAAb,cACU,WAEV;CACE;CAEA,YAAYA,QAAoC;EAC9C,MAAM,UAAU,CAAE,EAAC;EACnB,KAAK,aAAa,QAAQ,cAAc;CACzC;;;;;;CAOD,MAAM,eAAeC,WAA0C;AAC7D,SAAO,QAAQ,IAAI,UAAU,IAAI,CAAC,QAAQ,KAAK,WAAW,IAAI,CAAC,CAAC;CACjE;;;;;;;;CASD,MAAM,WAAWC,UAAqC;EACpD,IAAI,MAAM;EAGV,MAAM,IAAI,aAAa,CAAC,WAAW,YAAY,GAAG;EAGlD,MAAM,SAAS,IAAI,SAAS,KAAK;EACjC,MAAM,aAAa,WAAW,IAAI,IAAI,KAAK,aAAa;EACxD,MAAM,UAAU,IAAI,SAAS;EAC7B,MAAM,IAAI,OAAO,SAAS,IAAI;EAG9B,MAAM,YAAY,IAAI,SAAS,KAAK;EACpC,MAAM,WAAW,CAAE;AACnB,OAAK,IAAI,KAAK,GAAG,KAAK,IAAI,QAAQ,MAAM,WACtC,SAAS,KAAK,IAAI,MAAM,IAAI,KAAK,UAAU,CAAC;EAI9C,MAAMC,MAAgB,SAAS,IAAI,CAAC,MAAM;GACxC,IAAI,MAAM;AAEV,QAAK,IAAI,KAAK,GAAG,KAAK,EAAE,QAAQ,MAAM,GACpC,OAAO,MAAM,MAAM,IAAI,EAAE,WAAW,GAAG;GAIzC,MAAMC,QAAO,MAAM,KAAM;AACzB,UAAOA;EACR,EAAC;AAEF,SAAO;CACR;AACF;;;;;AAMD,IAAa,iBAAb,cAAoC,WAAW;CAC7C,YAAYC,QAA2B;EACrC,MAAM,UAAU,CAAE,EAAC;CACpB;;;;;;CAOD,eAAeJ,WAA0C;AACvD,SAAO,QAAQ,QAAQ,UAAU,IAAI,MAAM;GAAC;GAAK;GAAK;GAAK;EAAI,EAAC,CAAC;CAClE;;;;;;CAOD,WAAWK,GAA8B;AACvC,SAAO,QAAQ,QAAQ;GAAC;GAAK;GAAK;GAAK;EAAI,EAAC;CAC7C;AACF"}
|