import { CloseVectorEmbeddings } from "closevector-common"; export class CloseVectorFreeEmbeddings implements CloseVectorEmbeddings { key: string; constructor(fields: { key: string }) { this.key = fields.key; } async embeddingWithRetry(textList: string[]) { const key = this.key; async function createEmbeddings(textList: string[]) { let resp = await fetch( `https://vector-kv.mega-ug.uk/public/embeddings?accessKey=${key}`, { method: "POST", body: JSON.stringify(textList), } ); let data = await resp.json(); return (data as any).data; } const resp = (await createEmbeddings(textList)).map(x => { return x.embedding }) return resp; } embedDocuments(documents: string[]): Promise { return this.embeddingWithRetry(documents); } embedQuery(document: string): Promise { return this.embeddingWithRetry([document]).then((embeddings) => embeddings[0]); } }