langchain-gigachat
Version:
GigaChat integration for LangChain.js
78 lines (77 loc) • 2.93 kB
TypeScript
import { Embeddings, type EmbeddingsParams } from "@langchain/core/embeddings";
import { GigaChat, GigaChatClientConfig } from "gigachat";
/**
* Interface for GigachatEmbeddings parameters. Extends EmbeddingsParams and
* defines additional parameters specific to the GigaChat embeddings class.
*/
export interface GigaChatEmbeddingsParams extends EmbeddingsParams {
/**
* Prefix for embeddings
* @default {"Дано предложение, необходимо найти его парафраз \nпредложение: "}
*/
prefixQuery?: string;
/**
* Use prefix or not
* @default {false}
*/
usePrefixQuery?: boolean;
/**
* The maximum number of documents to embed in a single request.
* @default {512}
*/
batchSize?: number;
/**
* Whether to strip new lines from the input text. This is recommended,
* but may not be suitable for all use cases.
* @default {true}
*/
stripNewLines?: boolean;
/** Model name to use */
model?: string;
}
/**
* Class for generating embeddings using the GigaChat API.
* @example
* ```typescript
* // Embed a query using GigaChatEmbeddings to generate embeddings for a given text
* const model = new GigaChatEmbeddings();
* const res = await model.embedQuery(
* "What would be a good company name for a company that makes colorful socks?",
* );
* console.log({ res });
*
* ```
*/
export declare class GigaChatEmbeddings extends Embeddings implements GigaChatEmbeddingsParams {
prefixQuery: string;
usePrefixQuery: boolean;
batchSize: number;
stripNewLines: boolean;
model: string;
protected clientConfig: GigaChatClientConfig;
protected _client: GigaChat;
constructor(fields?: GigaChatEmbeddingsParams & GigaChatClientConfig);
/**
* Method to generate embeddings for an array of documents. Splits the
* documents into batches and makes requests to the OpenAI API to generate
* embeddings.
* @param texts Array of documents to generate embeddings for.
* @returns Promise that resolves to a 2D array of embeddings for each document.
*/
embedDocuments(texts: string[]): Promise<number[][]>;
/**
* Method to generate an embedding for a single document. Calls the
* embeddingWithRetry method with the document as the input.
* @param text Document to generate an embedding for.
* @returns Promise that resolves to an embedding for the document.
*/
embedQuery(text: string): Promise<number[]>;
/**
* Private method to make a request to the GigaChat API to generate
* embeddings. Handles the retry logic and returns the response from the
* API.
* @param input String or array of strings to embedding
* @returns Promise that resolves to the response from the API.
*/
protected embeddingWithRetry(input: string | Array<string>): Promise<any>;
}