fastrag-ranker / handler.py
IlyasMoutawwakil's picture
Update handler.py
f5d46f6 verified
raw
history blame contribute delete
626 Bytes
from typing import Any, Dict
from haystack import Document
from fastrag.rankers import IPEXBiEncoderSimilarityRanker
class EndpointHandler:
def __init__(self, path=""):
model_id = "Intel/bge-large-en-v1.5-rag-int8-static"
self.ranker = IPEXBiEncoderSimilarityRanker(model=model_id)
self.ranker.warm_up()
def __call__(self, data: Dict[str, Any]):
query = data.get("query")
documents = data.get("documents")
top_k = data.get("top_k", None)
documents = [Document.from_dict(doc) for doc in documents]
return self.ranker.run(query, documents, top_k)