Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add metadatas to embeddings #141

Merged
merged 7 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading