Skip to content

Commit

Permalink
✨ Add metadatas to embeddings (#141)
Browse files Browse the repository at this point in the history
* ✨ 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]>
  • Loading branch information
kevin-btc and lowczarc authored Jul 19, 2024
1 parent d5019a5 commit 138f1f1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
10 changes: 8 additions & 2 deletions lib/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ async function searchEmbeddings(
id: string,
input: string,
clientOptions: InputClientOptions = {},
): Promise<{ id: string; content: string; similarity: number }[]> {
): Promise<
{ id: string; content: string; similarity: number; metadatas: Record<string, unknown> }[]
> {
const { token, endpoint } = await defaultOptions(clientOptions);

try {
Expand Down Expand Up @@ -166,7 +168,11 @@ class Embeddings {
return this.memoryId;
}

async search(input: string): Promise<{ id: string; content: string; similarity: number }[]> {
async search(
input: string,
): Promise<
{ id: string; content: string; similarity: number; metadatas: Record<string, unknown> }[]
> {
const id = await this.memoryId;
return searchEmbeddings(id, input, await this.clientOptions);
}
Expand Down
1 change: 1 addition & 0 deletions lib/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export type Ressource = {
similarity: number;
id: string;
content: string;
metadatas?: Record<string, unknown>;
};

export type GenerationResult = {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polyfire-js",
"version": "0.2.59",
"version": "0.2.60",
"main": "index.js",
"types": "index.d.ts",
"author": "Lancelot Owczarczak <[email protected]>",
Expand Down
3 changes: 2 additions & 1 deletion tests/generation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ test(

const embeddings = Embeddings();

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

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

expect(message).toBe("banana42");
Expand Down

0 comments on commit 138f1f1

Please sign in to comment.