Skip to content

Commit

Permalink
rm class which shouldnt be moved
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Mar 30, 2024
1 parent f7d2ee1 commit 1e80ac2
Showing 1 changed file with 0 additions and 63 deletions.
63 changes: 0 additions & 63 deletions langchain-core/src/retrievers/document_compressors/base.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<DocumentInterface[]> {
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;
}
}

0 comments on commit 1e80ac2

Please sign in to comment.