import log from "loglevel"; import { Index } from "@pinecone-database/pinecone"; import { WeaviateClient } from "weaviate-ts-client"; type MetadataFilter = Record; type QueryMetadata = Record; export type Signal = { label: string; weight: number; }; type QueryResult = { vector: Vector; metadata?: QueryMetadata; score: number; id: string; }; type AlgorithmType = { type: 'SIMPLE'; } | { type: 'CUSTOM'; customId: string; } | { type: 'FACTORY'; factoryId: string; }; type Query = { embedding: Vector; top_k: number; top_k_mmr: number; filter: MetadataFilter; include_metadata: boolean; include_values: boolean; }; /** A Deterministic Finite Automata. */ type DFA = { signals?: Signal[]; nodes: { name: string; batch_type: BatchType; params: Partial; }[]; edges: { name: string; edge_type: 'BATCH' | 'DEFAULT' | (string & NonNullable); start: string; end: string; }[]; }; type WeightedVectors = { vectors: number[][]; weights: number[]; }; type Vector = number[]; type DistanceMetric = 'cosine_sim' | 'euclidean_dist' | 'dot_product'; type FetchResult = { vector: Vector; metadata: QueryMetadata; id: string; }; type BatchType = 'biased' | 'sampled' | 'random' | 'personalized'; type VertexParameters = { mu: number; alpha: number; r: number; last_n: number; n_topics: number; remove_duplicates: boolean; apply_threshold: number; apply_mmr: boolean; }; type Vertex = { name: string; batchType: BatchType; params: VertexParameters; }; /** Configuration for the FirstBatch User Embeddings SDK. */ export type FirstBatchConfig = Partial<{ batchSize: number; quantizerTrainSize: number; quantizerType: 'scalar' | 'product'; enableHistory: boolean; verbose: boolean; }>; declare const _default: { /** Default values. */ readonly DEFAULTS: { readonly QUANTIZER_TRAIN_SIZE: 100; readonly QUANTIZER_TYPE: "scalar"; readonly QUANTIZER_TOPK: 5; readonly EMBEDDING_LAST_N: 50; readonly EMBEDDING_SIZE: 1536; readonly DISTANCE_METRIC: "cosine_sim"; readonly CONFIDENCE_INTERVAL_RATIO: 0.15; readonly HISTORY_FIELD: "id"; readonly BATCH_SIZE: 10; readonly KEY: "text"; readonly ENABLE_HISTORY: false; readonly VERBOSE: false; readonly PARAMS: { mu: number; alpha: number; r: number; last_n: number; n_topics: number; remove_duplicates: true; apply_threshold: number; apply_mmr: false; }; }; /** Factor applied to TOPK when MMR is to be applied. */ readonly MMR_TOPK_FACTOR: 2; readonly MIN_TOPK: 5; /** Preset algorithm names. */ readonly PRESET_ALGORITHMS: { UNIQUE_JOURNEYS: string; CONTENT_CURATION: string; AI_AGENTS: string; RECOMMENDATIONS: string; NAVIGATION: string; }; }; declare const presetSignals: { readonly DEFAULT: { readonly label: "DEFAULT"; readonly weight: 1; }; readonly BATCH: { readonly label: "BATCH"; readonly weight: 0; }; readonly ADD_TO_CART: { readonly label: "ADD_TO_CART"; readonly weight: 16; }; readonly ITEM_VIEW: { readonly label: "ITEM_VIEW"; readonly weight: 10; }; readonly APPLY: { readonly label: "APPLY"; readonly weight: 18; }; readonly PURCHASE: { readonly label: "PURCHASE"; readonly weight: 20; }; readonly HIGHLIGHT: { readonly label: "HIGHLIGHT"; readonly weight: 8; }; readonly GLANCE_VIEW: { readonly label: "GLANCE_VIEW"; readonly weight: 14; }; readonly CAMPAIGN_CLICK: { readonly label: "CAMPAIGN_CLICK"; readonly weight: 6; }; readonly CATEGORY_VISIT: { readonly label: "CATEGORY_VISIT"; readonly weight: 10; }; readonly SHARE: { readonly label: "SHARE"; readonly weight: 10; }; readonly MERCHANT_VIEW: { readonly label: "MERCHANT_VIEW"; readonly weight: 10; }; readonly REIMBURSED: { readonly label: "REIMBURSED"; readonly weight: 20; }; readonly APPROVED: { readonly label: "APPROVED"; readonly weight: 18; }; readonly REJECTED: { readonly label: "REJECTED"; readonly weight: 18; }; readonly SHARE_ARTICLE: { readonly label: "SHARE_ARTICLE"; readonly weight: 10; }; readonly COMMENT: { readonly label: "COMMENT"; readonly weight: 12; }; readonly PERSPECTIVES_SWITCH: { readonly label: "PERSPECTIVES_SWITCH"; readonly weight: 8; }; readonly REPOST: { readonly label: "REPOST"; readonly weight: 20; }; readonly SUBSCRIBE: { readonly label: "SUBSCRIBE"; readonly weight: 18; }; readonly SHARE_PROFILE: { readonly label: "SHARE_PROFILE"; readonly weight: 10; }; readonly PAID_SUBSCRIBE: { readonly label: "PAID_SUBSCRIBE"; readonly weight: 20; }; readonly SAVE: { readonly label: "SAVE"; readonly weight: 8; }; readonly FOLLOW_TOPIC: { readonly label: "FOLLOW_TOPIC"; readonly weight: 10; }; readonly WATCH: { readonly label: "WATCH"; readonly weight: 20; }; readonly CLICK_LINK: { readonly label: "CLICK_LINK"; readonly weight: 6; }; readonly RECOMMEND: { readonly label: "RECOMMEND"; readonly weight: 12; }; readonly FOLLOW: { readonly label: "FOLLOW"; readonly weight: 10; }; readonly VISIT_PROFILE: { readonly label: "VISIT_PROFILE"; readonly weight: 12; }; readonly AUTO_PLAY: { readonly label: "AUTO_PLAY"; readonly weight: 4; }; readonly SAVE_ARTICLE: { readonly label: "SAVE_ARTICLE"; readonly weight: 8; }; readonly REPLAY: { readonly label: "REPLAY"; readonly weight: 20; }; readonly READ: { readonly label: "READ"; readonly weight: 14; }; readonly LIKE: { readonly label: "LIKE"; readonly weight: 8; }; readonly CLICK_EMAIL_LINK: { readonly label: "CLICK_EMAIL_LINK"; readonly weight: 6; }; readonly ADD_TO_LIST: { readonly label: "ADD_TO_LIST"; readonly weight: 12; }; readonly FOLLOW_AUTHOR: { readonly label: "FOLLOW_AUTHOR"; readonly weight: 10; }; readonly SEARCH: { readonly label: "SEARCH"; readonly weight: 15; }; readonly CLICK_AD: { readonly label: "CLICK_AD"; readonly weight: 6; }; }; /** Preset set of signals, you can use these or add your own signals to this object. */ export const Signals: Readonly<{ [signal in keyof typeof presetSignals]: Signal; }> & { [signal: string]: Signal; }; declare class FirstBatchAPI { /** TeamID of this client. */ teamId: string; /** Backend URL with respect to the region of the API key. */ url: string; /** Region for this client. */ region: string; /** Acts as a constructor. */ protected constructor(apiKey: string); /** Initializes vectorDB, returns error message as a response if there was one. */ protected initVectordbScalar(vdbid: string, quantizedVectors: number[][], quantiles: number[]): Promise<{ success: boolean; code: number; message?: string | undefined; data: string; }>; /** Initializes vectorDB, returns error message as a response if there was one. */ protected initVectordbProduct(vdbid: string, quantizedVectors: number[][], quantizedVectorResiduals: number[][], codebook: number[][], codebookResidual: number[][], M: number, Ks: number, Ds: number): Promise<{ success: boolean; code: number; message?: string | undefined; data: string; }>; /** Updates history, returns error message as a response if there was one. */ protected addHistory(sessionId: string, ids: string[]): Promise<{ success: boolean; code: number; message?: string | undefined; data: string; }>; protected createSession(algorithm: string, vdbid: string, options?: { customId?: string; factoryId?: string; sessionId?: string; hasEmbeddings?: string; }): Promise<{ success: boolean; code: number; message?: string | undefined; data: string; }>; /** Updates state, returns error message as a response if there was one. */ protected updateState(sessionId: string, state: string, batchType: Vertex['batchType']): Promise<{ success: boolean; code: number; message?: string | undefined; data: string; }>; /** Adds a signal, returns error message as a response if there was one. */ protected signal(sessionId: string, vector: number[], stateName: string, signal: Signal): Promise<{ success: boolean; code: number; message?: string | undefined; data: string; }>; protected biasedBatch(sessionId: string, vdbid: string, state: string, options?: { bias?: WeightedVectors; params?: Vertex['params']; }): Promise; protected sampledBatch(sessionId: string, vdbid: string, state: string, nTopics: number, params?: Record): Promise; protected getSession(sessionId: string): Promise<{ algorithm: AlgorithmType; state: string; vdbid: string; has_embeddings: boolean; factory_id?: string | undefined; custom_id?: string | undefined; }>; protected getHistory(sessionId: string): Promise; protected getUserEmbeddings(sessionId: string, lastN?: number): Promise; protected vdbExists(vdbid: string): Promise; /** * Retrieve the blueprint of some custom id. * * @param customId algorithm id * @returns a DFA (TODO: is this a string & object or always an object?) */ protected getCustomBlueprint(customId: string): Promise; /** Initialize the client. * * Retrieves the region for the set API key, and creates an Axios instance for the client. */ protected init(): Promise; } /** Base vector store implementation. * * Every integration must extend & implement this abstract class. */ declare abstract class VectorStore { embeddingSize: number; distanceMetric: DistanceMetric; protected readonly historyField: string; constructor(options?: { embeddingSize?: number; distanceMetric?: DistanceMetric; historyField?: string; }); multiSearch(queries: Query[]): Promise; multiFetch(ids: string[]): Promise; abstract search(query: Query): Promise; abstract fetch(id: string): Promise; abstract historyFilter(ids: string[], prevFilter?: object): MetadataFilter; } export class FirstBatch extends FirstBatchAPI { readonly batchSize: number; readonly quantizerTrainSize: number; readonly quantizerType: 'scalar' | 'product'; readonly enableHistory: boolean; readonly verbose: boolean; logger: log.Logger; constructor(apiKey: string, config?: FirstBatchConfig); static new(apiKey: string, config?: FirstBatchConfig): Promise; /** Add a vector store to the container. * * If this vector store has not beed registered to the API before, * it will be "sketched" with respect to the `quantizerType`, which may take some time. * * @param vdbid vectorDB ID of your choice * @param vectorStore a `VectorStore` instance */ addVectorStore(name: string, vectorStore: VectorStore): Promise; /** * Fetches the user embeddings for a specific session. * * @param session session object * @returns vectors and weights */ userEmbeddings(sessionId: string): Promise; /** * Creates a new session with the provided parameters & vector database ID. * This method returns the sessionID; however, you can provide the sessionID with this method to create a persistent session. * * @param algorithm algorithm label * @param vdbid vectorDB id * @param options optional `sessionId` or `customId` * - if `sessionId` is given, a persistent-session will be created and this same id will be returned * - `customId` is only expected when `algorithm = 'CUSTOM'` * @returns session object */ session(algorithm: keyof typeof constants.PRESET_ALGORITHMS | 'SIMPLE' | 'CUSTOM', vdbid: string, options?: { sessionId?: string; customId?: string; }): Promise; /** * Add a signal to current session. * * @param session session object * @param signal a {@link Signal} * @param contentId id of a returned item from batch * @returns `true` is signal was added succesfully */ addSignal(sessionId: string, signal: Signal, contentId: string): Promise<{ source: import("types").Vertex; destination: import("types").Vertex; success: boolean; }>; /** * Get a new batch. * * @param session session object * @param options optional batch size, and bias parameters (vectors and weights) * @returns ids and metadata */ batch(sessionId: string, options?: { batchSize?: number; bias?: WeightedVectors; }): Promise<[string[], QueryMetadata[]]>; } export class Pinecone extends VectorStore { index: Index; /** * @param index a Pinecone index * @param namespace (optional) namespace * @param distanceMetric (optional) distance metric, defaults to cosine similarity */ constructor(index: Index, kwargs?: { historyField?: string; embeddingSize?: number; distanceMetric?: DistanceMetric; }); search(query: Query): Promise; fetch(id: string): Promise<{ vector: import("@pinecone-database/pinecone").RecordValues; metadata: import("@pinecone-database/pinecone").RecordMetadata; id: string; }>; historyFilter(ids: string[], prevFilter?: object): MetadataFilter; } export class Weaviate extends VectorStore { /** A wrapper for the Weaviate client. * @param client a Weaviate client * @param className (optional) className name * @param outputFields (optional) an array of field names for outputs * @param historyField (optional) the name of the `id` field for history filtering * @param distanceMetric (optional) optional distance metric, defaults to cosine similarity */ constructor(client: WeaviateClient, kwargs?: { className?: string; outputFields?: string[]; embeddingSize?: number; historyField?: string; distanceMetric?: DistanceMetric; }); search(query: Query, options?: { additional?: string; }): Promise; fetch(id: string): Promise; historyFilter(ids: string[], prevFilter?: { operands: any[]; operator: string; }): MetadataFilter; } //# sourceMappingURL=index.d.ts.map