@forge-ml/rag
Version:
A RAG (Retrieval-Augmented Generation) package for Forge ML
23 lines (22 loc) • 810 B
JavaScript
import { embed } from "@nomic-ai/atlas";
class NomicEmbedder {
apiKey;
//@TODO set api key with AtlasUser and make api calls instead
constructor({ apiKey }) {
this.apiKey = apiKey;
}
async generateEmbedding(text) {
const embedding = await embed(text, { model: "nomic-embed-text-v1.5" }, this.apiKey);
return embedding;
}
async embedChunks(chunks, documentId) {
const embeddings = await embed(chunks.map((chunk) => chunk.text), { model: "nomic-embed-text-v1.5" }, this.apiKey);
const embeddedChunks = chunks.map((chunk, index) => ({
chunkId: chunk.forgeMetadata.chunkId,
documentId: documentId,
embedding: embeddings[index],
}));
return embeddedChunks;
}
}
export default NomicEmbedder;