Class that represents a document compressor that uses embeddings to drop documents unrelated to the query.

Example

const embeddingsFilter = new EmbeddingsFilter({
embeddings: new OpenAIEmbeddings(),
similarityThreshold: 0.8,
k: 5,
});
const retrievedDocs = await embeddingsFilter.filterDocuments(
getDocuments(),
"What did the speaker say about Justice Breyer in the 2022 State of the Union?",
);
console.log({ retrievedDocs });

Hierarchy

Constructors

Properties

embeddings: EmbeddingsInterface

Embeddings to use for embedding document contents and queries.

similarityFn: any = cosineSimilarity

Similarity function for comparing documents.

k?: number = 20

The number of relevant documents to return. Can be explicitly set to undefined, in which case similarity_threshold` must be specified. Defaults to 20

similarityThreshold?: number

Threshold for determining when two documents are similar enough to be considered redundant. Must be specified if k is not set.

Methods

  • Abstract method that must be implemented by any class that extends BaseDocumentCompressor. This method takes an array of Document objects and a query string as parameters and returns a Promise that resolves with an array of compressed Document objects.

    Parameters

    • documents: DocumentInterface[]

      An array of Document objects to be compressed.

    • query: string

      A query string.

    Returns Promise<DocumentInterface[]>

    A Promise that resolves with an array of compressed Document objects.

Generated using TypeDoc