HuggingFaceCrossEncoder Issue: RuntimeError: The expanded size of the tensor (614) must match the existing size (512) at non-singleton dimension 1 #21812
Labels
🤖:bug
Related to a bug, vulnerability, unexpected error with an existing feature
🔌: huggingface
Primarily related to HuggingFace integrations
Checked other resources
Example Code
from langchain_community.cross_encoders import HuggingFaceCrossEncoder
reranking_model = HuggingFaceCrossEncoder(model_name="cross-encoder/msmarco-MiniLM-L12-en-de-v1")
def load_retriever(embeddings,
collection_name,
CONNECTION_STRING,
use_parent_retriever=cfg.USE_PARENT_RETRIEVER,
use_colbert=cfg.USE_COLBERT,
use_cross_encoder = cfg.USE_CROSS_ENCODER,
reranking_model=None):
# Basic Retriever
if use_parent_retriever == False:
db = load_PG_vectorstore(embeddings=embeddings, COLLECTION_NAME=collection_name, CONNECTION_STRING=CONNECTION_STRING)
retriever = db.as_retriever(search_kwargs={'k': cfg.VECTOR_COUNT, 'score_threshold': cfg.SCORE_THRESHOLD}, search_type="similarity_score_threshold")
Error Message and Stack Trace (if applicable)
RuntimeError: The expanded size of the tensor (614) must match the existing size (512) at non-singleton dimension 1. Target sizes: [20, 614]. Tensor sizes: [1, 512]
Description
Hi,
I am using HuggingFaceCrossEncoder to rerank my retriever results for RAG. Generally it works but for some retrieval results I am getting the described error message. I checked the issue and assume that my input is too long as the max_tokens of the model "cross-encoder/msmarco-MiniLM-L12-en-de-v1" is 512.
Therefore I want to truncate the input in order to make it work, but found no solution when reading the docs.
Is this possible to do? Otherwise I have to stick to ColBERT for Reranking, there I don't see this issue.
System Info
langchain version: 0.1.17
langchain-community version: 0.0.36
The text was updated successfully, but these errors were encountered: