diff --git a/langchain-core/src/retrievers/document_compressors/base.ts b/langchain-core/src/retrievers/document_compressors/base.ts index 05cdd3a4d1f5..0f48febe1a69 100644 --- a/langchain-core/src/retrievers/document_compressors/base.ts +++ b/langchain-core/src/retrievers/document_compressors/base.ts @@ -1,6 +1,5 @@ import { Callbacks } from "../../callbacks/manager.js"; import { DocumentInterface } from "../../documents/document.js"; -import { BaseDocumentTransformer } from "../../documents/transformers.js"; /** * Base Document Compression class. All compressors should extend this class. @@ -26,65 +25,3 @@ export abstract class BaseDocumentCompressor { return x?.compressDocuments !== undefined; } } - -/** - * Document compressor that uses a pipeline of Transformers. - * @example - * ```typescript - * const compressorPipeline = new DocumentCompressorPipeline({ - * transformers: [ - * new RecursiveCharacterTextSplitter({ - * chunkSize: 200, - * chunkOverlap: 0, - * }), - * new EmbeddingsFilter({ - * embeddings: new OpenAIEmbeddings(), - * similarityThreshold: 0.8, - * k: 5, - * }), - * ], - * }); - * const retriever = new ContextualCompressionRetriever({ - * baseCompressor: compressorPipeline, - * baseRetriever: new TavilySearchAPIRetriever({ - * includeRawContent: true, - * }), - * }); - * const retrievedDocs = await retriever.getRelevantDocuments( - * "What did the speaker say about Justice Breyer in the 2022 State of the Union?", - * ); - * console.log({ retrievedDocs }); - * ``` - */ -export class DocumentCompressorPipeline extends BaseDocumentCompressor { - transformers: (BaseDocumentTransformer | BaseDocumentCompressor)[]; - - constructor(fields: { - transformers: (BaseDocumentTransformer | BaseDocumentCompressor)[]; - }) { - super(); - this.transformers = fields.transformers; - } - - async compressDocuments( - documents: DocumentInterface[], - query: string, - callbacks?: Callbacks - ): Promise { - let transformedDocuments = documents; - for (const transformer of this.transformers) { - if (BaseDocumentCompressor.isBaseDocumentCompressor(transformer)) { - transformedDocuments = await transformer.compressDocuments( - transformedDocuments, - query, - callbacks - ); - } else { - transformedDocuments = await transformer.transformDocuments( - transformedDocuments - ); - } - } - return transformedDocuments; - } -}