How return id from ConvexVectorStore.fromDocuments #6351
Unanswered
teomikitenko
asked this question in
Q&A
Replies: 1 comment
-
To determine the ID provided by the database for an embedding when using /**
* Method to add documents to the Xata database. Maps the page content of
* each document, embeds the documents using the embeddings, and adds the
* vectors to the database.
* @param documents Array of documents to be added.
* @param options Optional object containing an array of ids.
* @returns Promise resolving to an array of ids of the added documents.
*/
async addDocuments(documents: Document[], options?: { ids?: string[] }) {
const texts = documents.map(({ pageContent }) => pageContent);
return this.addVectors(
await this.embeddings.embedDocuments(texts),
documents,
options
);
}
/**
* Method to add vectors to the Xata database. Maps each vector to a row
* with the document's content, embedding, and metadata. Creates or
* replaces these rows in the Xata database.
* @param vectors Array of vectors to be added.
* @param documents Array of documents corresponding to the vectors.
* @param options Optional object containing an array of ids.
* @returns Promise resolving to an array of ids of the added vectors.
*/
async addVectors(
vectors: number[][],
documents: Document[],
options?: { ids?: string[] }
) {
const rows = vectors
.map((embedding, idx) => ({
content: documents[idx].pageContent,
embedding,
...documents[idx].metadata,
}))
.map((row, idx) => {
if (options?.ids) {
return { id: options.ids[idx], ...row };
}
return row;
});
const res = await this.client.db[this.table].createOrReplace(rows);
const results = res as unknown as { id: string }[];
const returnedIds = results.map((row) => row.id);
return returnedIds;
} When you call |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
_I write embedding using Convex
const vectoreStore = await ConvexVectorStore.fromDocuments(splitDocs, embeddings, { ctx });
how do I determine the ID provided by the database for this embed . My application use this ID for search current embeddings - but i dont see information about this in documentation. How i do this using Convex Vectore Storeusing LangchainJS in Next.js and Convex
nodejs -v20.15.1
windows 10_
Beta Was this translation helpful? Give feedback.
All reactions