Skip to content

Commit

Permalink
Unshittify the vectorSearch function
Browse files Browse the repository at this point in the history
  • Loading branch information
Mansive committed Jan 8, 2024
1 parent 14128ae commit 81b2759
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/lib/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export async function search(query: string) {
}

export async function vectorSearch(query: string) {
// Is this how JavaScript experts write functions?
return await fetch("https://api.embaas.io/v1/embeddings/", {
const results = await fetch("https://api.embaas.io/v1/embeddings/", {
method: "POST",
body: JSON.stringify({
texts: ["query: " + query],
Expand All @@ -23,16 +22,16 @@ export async function vectorSearch(query: string) {
"Content-Type": "application/json",
Authorization: "Bearer " + process.env.EMBAAS_API_KEY,
},
})
.then((response) => response.json())
.then((embeddings) =>
xata.db.Books.vectorSearch(
"embeddings",
embeddings["data"][0]["embedding"],
{
similarityFunction: "cosineSimilarity",
size: 35,
}
)
);
});

const embeddings = await results.json();

return await xata.db.Books.vectorSearch(
"embeddings",
embeddings["data"][0]["embedding"],
{
similarityFunction: "cosineSimilarity",
size: 35,
}
);
}

0 comments on commit 81b2759

Please sign in to comment.