@gentrace/pinecone
Version:
Gentrace Pinecone v1 plugin for Node.JS
100 lines (99 loc) • 5.38 kB
TypeScript
import { Context, Configuration as GentraceConfiguration, PipelineRun, StepRun } from "@gentrace/core";
import { DeleteManyOptions, DeleteOneOptions, FetchOptions, FetchResponse, Index, Pinecone, PineconeConfiguration, PineconeRecord, QueryOptions, QueryResponse, RecordMetadata, UpdateOptions } from "@pinecone-database/pinecone";
export type GentraceParams = {
pipelineSlug?: string;
gentrace?: Context;
};
type PineconePipelineHandlerOptions = {
pipelineRun?: PipelineRun;
config?: PineconeConfiguration;
gentraceConfig: GentraceConfiguration;
};
export type ModifyFirstParam<T, U> = T extends (param1: infer P, ...args: infer A) => infer R ? (param1: U, ...args: A) => R : never;
export type ModifySecondParam<T, U> = T extends (param1: infer P1, param2: infer P2, ...args: infer A) => infer R ? (param1: P1, param2?: U, ...args: A) => R : never;
export type ModifyReturnType<T, NewReturn> = T extends (...args: infer A) => infer R ? (...args: A) => NewReturn : never;
type AppendGentraceParams<F extends (...args: any[]) => any> = (...args: [...Parameters<F>, GentraceParams?]) => ReturnType<F>;
type FetchFunctionType = typeof Index.prototype.fetch;
type ModifiedFetchFunction = FunctionWithPipelineRunId<AppendGentraceParams<FetchFunctionType>>;
type UpdateFunctionType = typeof Index.prototype.update;
type ModifiedUpdateFunction = FunctionWithPipelineRunId<ModifyFirstParam<UpdateFunctionType, UpdateOptions & GentraceParams>>;
type QueryFunctionType = typeof Index.prototype.query;
type ModifiedQueryFunction = FunctionWithPipelineRunId<ModifyFirstParam<QueryFunctionType, QueryOptions & GentraceParams>>;
type UpsertFunctionType = typeof Index.prototype.upsert;
type ModifiedUpsertFunction = FunctionWithPipelineRunId<AppendGentraceParams<UpsertFunctionType>>;
type DeleteOneFunctionType = typeof Index.prototype.deleteOne;
type ModifiedDeleteOneFunction = FunctionWithPipelineRunId<AppendGentraceParams<DeleteOneFunctionType>>;
type DeleteManyFunctionType = typeof Index.prototype.deleteMany;
type ModifiedDeleteManyFunction = FunctionWithPipelineRunId<AppendGentraceParams<DeleteManyFunctionType>>;
type DeleteAllFunctionType = typeof Index.prototype.deleteAll;
type ModifiedDeleteAllFunction = FunctionWithPipelineRunId<AppendGentraceParams<DeleteAllFunctionType>>;
export type ModifiedNamespaceFunction = (namespace: string) => ModifiedIndex;
export type ModifiedIndex = Omit<Index, "fetch" | "update" | "query" | "upsert" | "deleteOne"> & {
fetch: ModifiedFetchFunction;
update: ModifiedUpdateFunction;
query: ModifiedQueryFunction;
upsert: ModifiedUpsertFunction;
deleteOne: ModifiedDeleteOneFunction;
deleteMany: ModifiedDeleteManyFunction;
deleteAll: ModifiedDeleteAllFunction;
namespace: ModifiedNamespaceFunction;
};
export type FunctionWithPipelineRunId<T extends (...args: any[]) => any> = (...args: Parameters<T>) => Promise<Awaited<ReturnType<T>> & {
pipelineRunId: string;
}>;
export declare class PineconePipelineHandler extends Pinecone {
protected pipelineRun?: PipelineRun;
protected gentraceConfig: GentraceConfiguration;
protected configProtected?: PineconeConfiguration;
constructor({ pipelineRun, config, gentraceConfig, }: PineconePipelineHandlerOptions);
setPipelineRun(pipelineRun: PipelineRun): void;
private setupSelfContainedPipelineRun;
indexInner<T extends RecordMetadata = RecordMetadata>(index: string, namespace?: string): ModifiedIndex;
}
export declare class PineconeFetchStepRun extends StepRun {
inputs: {
ids: FetchOptions;
};
response: FetchResponse;
constructor(elapsedTime: number, startTime: string, endTime: string, inputs: {
ids: FetchOptions;
}, response: FetchResponse, context: Context);
}
export declare class PineconeQueryStepRun extends StepRun {
inputs: QueryOptions;
response: QueryResponse;
constructor(elapsedTime: number, startTime: string, endTime: string, inputs: Omit<QueryOptions, "topK" | "filter">, modelParams: Pick<QueryOptions, "topK" | "filter">, response: QueryResponse, context: Context);
}
export declare class PineconeUpdateStepRun extends StepRun {
inputs: UpdateOptions;
response: object;
constructor(elapsedTime: number, startTime: string, endTime: string, inputs: UpdateOptions, response: object, context: Context);
}
export declare class PineconeUpsertStepRun extends StepRun {
inputs: {
records: PineconeRecord<RecordMetadata>[];
};
response: any;
constructor(elapsedTime: number, startTime: string, endTime: string, inputs: {
records: PineconeRecord<RecordMetadata>[];
}, context: Context);
}
export declare class PineconeDeleteOneStepRun extends StepRun {
inputs: DeleteOneOptions;
response: object;
constructor(elapsedTime: number, startTime: string, endTime: string, inputs: {
recordId: DeleteOneOptions;
}, context: Context);
}
export declare class PineconeDeleteManyStepRun extends StepRun {
inputs: DeleteManyOptions;
response: object;
constructor(elapsedTime: number, startTime: string, endTime: string, inputs: {
options: DeleteManyOptions;
}, context: Context);
}
export declare class PineconeDeleteAllStepRun extends StepRun {
response: object;
constructor(elapsedTime: number, startTime: string, endTime: string, context: Context);
}
export {};