Repository: langchain
Issue: unable to set max_token_limit in then create_retrieval_chain function when using ContextualCompressionRetriever to compress documents.
Labels: Ɑ:  core

### Checked other resources

- [X] I added a very descriptive title to this issue.
- [X] I searched the LangChain documentation with the integrated search.
- [X] I used the GitHub search to find a similar question and didn't find it.
- [X] I am sure that this is a bug in LangChain rather than my code.
- [X] The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

### Example Code

```python
from langchain_core.retrievers import BaseRetriever
from langchain.retrievers import ContextualCompressionRetriever
from langchain_community.document_compressors import LLMLinguaCompressor
from GPUtil import getAvailable
from langchain_core.documents import Document
from langchain_core.embeddings.embeddings import Embeddings
from typing import Any, List
from pydantic import BaseModel
from langchain_qdrant import FastEmbedSparse, QdrantVectorStore, RetrievalMode
from qdrant_client import QdrantClient, models
from qdrant_client.http.models import Distance
from langchain_google_genai import (
    ChatGoogleGenerativeAI, 
    HarmBlockThreshold, 
    HarmCategory
)

sparse_embedding = FastEmbedSparse(model_name="Qdrant/bm25")
sparse_vector_params = { 
    "index": models.SparseIndexParams(on_disk=False)
}
quantization_config = models.ScalarQuantization(
    scalar = models.ScalarQuantizationConfig(
        type=models.ScalarType.INT8,
        quantile=0.99,
        always_ram=True,
    )
)

def create_compression_retriever(retriever: BaseRetriever):
    device_map = "cuda" if getAvailable() else "cpu"
    model_name="openai-community/gpt2"
    compressor = LLMLinguaCompressor(model_name=model_name, device_map=device_map)

    return ContextualCompressionRetriever(base_compressor=compressor, base_retriever=retriever)

google_api_key = ''
model = 'gemini-1.5-flash-002'
embedding = GoogleGenerativeAIEmbeddings(
            model = model, 
            google_api_key = google_api_key
)
collection_name='test_collection'

text_splitter = RecursiveCharacterTextSplitter(
    chunk_size=500,
    chunk_overlap=10,
)

documents = []
for pdf_file in pdf_files:
      loader = PyPDFLoader(file_path=pdf_file)  # Create a loader for each PDF
        docs = loader.load_and_split(text_splitter=text_splitter)  # Load documents from the PDF
        documents.extend(docs)

client = QdrantClient(url='http://localhost:6333')
store = QdrantVectorStore.construct_instance(
            client_options={ "url": "http://localhost:6333" },
            embedding=embedding,
            sparse_embedding=sparse_embedding,
            collection_name=collection_name,
            retrieval_mode=RetrievalMode.HYBRID,
            force_recreate=True,
            sparse_vector_params=sparse_vector_params,
            distance=Distance.COSINE
)
client.update_collection(collection_name=collection_name,  quantization_config=quantization_config)
store.add_documents(documents)
retriever = create_compression_retriever(retriever=store.as_retriever())
system_prompt_with_context = (
            "You are an expert in ESG reporting."
            "\n\n"
            "{context}"
        )
qa_prompt = ChatPromptTemplate.from_messages(
            [
                ("system", system_prompt_with_context),
                 MessagesPlaceholder("chat_history"),
                ("human", "{input}")
            ]
)
llm = ChatGoogleGenerativeAI(
            model='gemini-1.5-flash-002',
            api_key=<api key>,
            max_tokens=2048,
            temperature=0.2,
            top_k=3,
            top_p=0.75,
            verbose=True,
            safety_settings={
                HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE, 
                HarmCategory.HARM_CATEGORY_HATE_SPEECH: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE, 
                HarmCategory.HARM_CATEGORY_HARASSMENT: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE, 
                HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE,
            }
)
question_answer_chain = create_stuff_documents_chain(llm=llm, prompt=qa_prompt)
chain = create_retrieval_chain(retriever=retriever, combine_docs_chain=question_answer_chain)
answer = chain.invoke({ input: "What is a ISSB reporting?")
print (answer)
```



### Error Message and Stack Trace (if applicable)

Token indices sequence length is longer than the specified maximum sequence length for this model (1059 > 1024). Running this sequence through the model will result in indexing errors"

### Description

I want to use lang chain's ContextualCompressionRetriever to compress the documents and use the compressed data as the LLM's context information. However, the LLM throws "Token indices sequence length is longer than the specified maximum sequence length for this model (1059 > 1024). Running this sequence through the model will result in indexing errors", and I am unable to set the max_token_limit in create_retrieval_chain.

### System Info


System Information
------------------
> OS:  Linux
> OS Version:  #48~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Oct  7 11:24:13 UTC 2
> Python Version:  3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0]

Package Information
-------------------
> langchain_core: 0.3.10
> langchain: 0.3.3
> langchain_community: 0.3.2
> langsmith: 0.1.131
> langchain_chroma: 0.1.4
> langchain_google_genai: 2.0.1
> langchain_ollama: 0.2.0
> langchain_openai: 0.2.2
> langchain_qdrant: 0.1.4
> langchain_text_splitters: 0.3.0
> langgraph: 0.2.37

Optional packages not installed
-------------------------------
> langserve

Other Dependencies
------------------
> aiohttp: 3.10.9
> async-timeout: 4.0.3
> chromadb: 0.5.11
> dataclasses-json: 0.6.7
> fastapi: 0.115.0
> fastembed: 0.4.1
> google-generativeai: 0.8.3
> httpx: 0.27.2
> jsonpatch: 1.33
> langgraph-checkpoint: 2.0.1
> langgraph-sdk: 0.1.33
> numpy: 1.26.4
> ollama: 0.3.3
> openai: 1.51.0
> orjson: 3.10.7
> packaging: 24.1
> pillow: 10.4.0
> pydantic: 2.9.2
> pydantic-settings: 2.5.2
> PyYAML: 6.0.2
> qdrant-client: 1.12.1
> requests: 2.32.3
> requests-toolbelt: 1.0.0
> SQLAlchemy: 2.0.35
> tenacity: 8.5.0
> tiktoken: 0.8.0
> typing-extensions: 4.12.2