-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathbase.ts
40 lines (35 loc) · 1.32 KB
/
base.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { AsyncCaller, AsyncCallerParams } from "../util/async_caller.js";
/**
* The parameters required to initialize an instance of the Embeddings
* class.
*/
export type EmbeddingsParams = AsyncCallerParams;
/**
* An abstract class that provides methods for embedding documents and
* queries using LangChain.
*/
export abstract class Embeddings {
/**
* The async caller should be used by subclasses to make any async calls,
* which will thus benefit from the concurrency and retry logic.
*/
caller: AsyncCaller;
constructor(params: EmbeddingsParams) {
this.caller = new AsyncCaller(params ?? {});
}
/**
* An abstract method that takes an array of documents as input and
* returns a promise that resolves to an array of vectors for each
* document.
* @param documents An array of documents to be embedded.
* @returns A promise that resolves to an array of vectors for each document.
*/
abstract embedDocuments(documents: string[]): Promise<number[][]>;
/**
* An abstract method that takes a single document as input and returns a
* promise that resolves to a vector for the query document.
* @param document A single document to be embedded.
* @returns A promise that resolves to a vector for the query document.
*/
abstract embedQuery(document: string): Promise<number[]>;
}