LLMLingua icon indicating copy to clipboard operation
LLMLingua copied to clipboard

how can i use it in langchain?

Open whm233 opened this issue 1 year ago • 1 comments

code like this:

prompt = PromptTemplate(template=prompt_template, input_variables=["context", "question"]) kc = RetrievalQA.from_llm(llm=qwllm, retriever=compression_retriever, prompt=prompt)

whm233 avatar Dec 21 '23 03:12 whm233

Hi @whm233, thank you for your support and interest in LLMLingua. Although I'm not an expert in LangChain, based on my experience, I believe its usage in LangChain should be similar to that in LlamaIndex, i.e., operating at the Postprocessor-level or reranker-level.

I briefly reviewed the LangChain pipeline and think you'll need to extend the BaseDocumentCompressor to implement a class similar to CohereRerank, as seen here: https://github.com/langchain-ai/langchain/tree/master/libs/langchain/langchain/retrievers/document_compressors/cohere_rerank.py.

Afterward, use ContextualCompressionRetriever() to replace the compression_retriever.

Thank you again for your interest.

iofu728 avatar Dec 21 '23 14:12 iofu728

Thanks to @thehapyone's contribution, LLMLingua is now available in Langchain. You can follow this notebook for guidance.

iofu728 avatar Feb 28 '24 03:02 iofu728