Skip to content

Resolve 8475 support rerank model from infinity #10939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _invoke(

# TODO: Do we need truncate docs to avoid llama.cpp return error?

data = {"model": model_name, "query": query, "documents": docs, "top_n": top_n}
data = {"model": model_name, "query": query, "documents": docs, "top_n": top_n, "return_documents": True}

try:
response = post(str(URL(url) / "rerank"), headers=headers, data=dumps(data), timeout=60)
Expand All @@ -83,7 +83,13 @@ def _invoke(
index = result["index"]

# Retrieve document text (fallback if llama.cpp rerank doesn't return it)
text = result.get("document", {}).get("text", docs[index])
text = docs[index]
document = result.get("document", {})
if document:
if isinstance(document, dict):
text = document.get("text", docs[index])
elif isinstance(document, str):
text = document

# Normalize the score
normalized_score = (result["relevance_score"] - min_score) / score_range
Expand Down