import { AtlasViewer } from './viewer.js'; import { BaseAtlasClass, AtlasUser } from './user.js'; type TaskType = 'search_document' | 'search_query' | 'clustering' | 'classification'; type EmbedderOptions = { model?: EmbeddingModel; maxTokens?: number; taskType?: TaskType; }; type EmbeddingModel = 'nomic-embed-text-v1' | 'nomic-embed-text-v1.5'; type Embedding = number[]; /** * A class that pools and runs requests to the Nomic embedding API. * If you are dispatching dozens or more embedding requests in quick * succession, this class handles pooling and backoff to ensure you get * your results as quickly as possible. * * For best results, **do not await your embedding results until they are needed**. * * For example, if you are embedding 1000 lines of text, you can do the * following: * * GOOD -- Nomic will break down your big request into multiple medium-sized ones. * ```js * const documents = ["Once upon a time", "there was a girl named Goldilocks", …, "and they all lived happily ever after"] * const embedder = new Embedder(myApiKey) * const embeddings = await embedder.embed(documents) * ``` * * GOOD -- Nomic will combine your small requests into several medium-size ones. * ```js * const documents = ["Once upon a time", "there was a girl named Goldilocks", …, "and they all lived happily ever after"] * const embedder = new Embedder(myApiKey) * const promises = [] * for (let document of documents) { * promises.push(embedder.embed(document)) * } * const embeddings = await Promise.all(promises) * ``` * * BAD -- You will generate many small, inefficient requests. * ```js * * const documents = ["Once upon a time", "there was a girl named Goldilocks", …, "and they all lived happily ever after"] * const embedder = new Embedder(myApiKey) * const embeddings = [] * for (let document of documents) { * const embedding = await embedder.embed(document); // <- premature await. * embeddings.push(embedding); * } * ``` */ export declare class Embedder extends BaseAtlasClass<{}> { model: EmbeddingModel; private embedQueue; tokensUsed: number; taskType: TaskType; private backoff; private epitaph?; private nextScheduledFlush; /** * * @param apiKey Your nomic API key, beginning with 'nk'. * @param user (Optionally) * @param options */ constructor(apiKey: string, options: EmbedderOptions); constructor(user: AtlasUser, options: EmbedderOptions); constructor(viewer: AtlasViewer, options: EmbedderOptions); protected endpoint(): string; private _embed; private flushDeferredEmbeddings; private periodicallyFlushCache; embed(value: string): Promise; embed(value: string[]): Promise; } export declare function embed(value: string, options: EmbedderOptions, apiKey: string | undefined): Promise; export declare function embed(values: string[], options: EmbedderOptions, apiKey: string | undefined): Promise; export {};