UNPKG

askexperts

Version:

AskExperts SDK: build and use AI experts - ask them questions and pay with bitcoin on an open protocol

51 lines (50 loc) 1.68 kB
import { Chunk, RagEmbeddings } from "./interfaces.js"; /** * Implementation of RagEmbeddings using Xenova transformers library. */ export declare class XenovaEmbeddings implements RagEmbeddings { private model; private embedder; private chunkSize; private chunkOverlap; static DEFAULT_MODEL: string; /** * Creates a new instance of XenovaEmbeddings. * @param model The model name to use for embeddings * @param chunkSize The size of text chunks to create * @param chunkOverlap The amount of overlap between chunks */ constructor(model?: string, // 'nomic-ai/nomic-embed-text-v1' chunkSize?: number, chunkOverlap?: number); /** * Initializes the embedder pipeline. * Must be called before using the embed method. * @throws Error if already initialized */ start(): Promise<void>; /** * Returns the name of the model used for embeddings * @returns The model name */ getModelName(): string; getVectorSize(): Promise<number>; /** * Splits text into chunks with specified size and overlap. * @param text The text to split * @returns Array of chunks */ private splitTextIntoChunks; /** * Embeds a single chunk of text. * @param text The text to embed * @returns The embedding vector * @throws Error if start() has not been called */ private embedText; /** * Embeds the given text by splitting it into chunks and generating embeddings. * @param text The text to embed * @returns Promise resolving to an array of chunks with their embeddings */ embed(text: string): Promise<Chunk[]>; }