Skip to content

Commit 138f1f1

Browse files
kevin-btclowczarc
andauthored
✨ Add metadatas to embeddings (#141)
* ✨ Add metadatas to embeddings * fix any in Record * add missing metadatas in Ressources type * change one test to use gpt-4o because gpt-3.5 is now dumb * ✅ tests: Fix memory test to await embedding * ✅ tests: Oopsie * up patch version --------- Co-authored-by: Lancelot Owczarczak <[email protected]>
1 parent d5019a5 commit 138f1f1

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

lib/embeddings.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ async function searchEmbeddings(
9292
id: string,
9393
input: string,
9494
clientOptions: InputClientOptions = {},
95-
): Promise<{ id: string; content: string; similarity: number }[]> {
95+
): Promise<
96+
{ id: string; content: string; similarity: number; metadatas: Record<string, unknown> }[]
97+
> {
9698
const { token, endpoint } = await defaultOptions(clientOptions);
9799

98100
try {
@@ -166,7 +168,11 @@ class Embeddings {
166168
return this.memoryId;
167169
}
168170

169-
async search(input: string): Promise<{ id: string; content: string; similarity: number }[]> {
171+
async search(
172+
input: string,
173+
): Promise<
174+
{ id: string; content: string; similarity: number; metadatas: Record<string, unknown> }[]
175+
> {
170176
const id = await this.memoryId;
171177
return searchEmbeddings(id, input, await this.clientOptions);
172178
}

lib/generate.ts

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export type Ressource = {
110110
similarity: number;
111111
id: string;
112112
content: string;
113+
metadatas?: Record<string, unknown>;
113114
};
114115

115116
export type GenerationResult = {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "polyfire-js",
3-
"version": "0.2.59",
3+
"version": "0.2.60",
44
"main": "index.js",
55
"types": "index.d.ts",
66
"author": "Lancelot Owczarczak <[email protected]>",

tests/generation.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,13 @@ test(
8686

8787
const embeddings = Embeddings();
8888

89-
embeddings.add('The word you have to remember is "banana42"');
89+
await embeddings.add('The word you have to remember is "banana42"');
9090

9191
const message = await generate("Just answer with the word you have to remember", {
9292
temperature: 0,
9393
cache: false,
9494
embeddings,
95+
model: "gpt-3.5-turbo",
9596
});
9697

9798
expect(message).toBe("banana42");

0 commit comments

Comments
 (0)