protocol.py
1 from __future__ import annotations 2 3 from typing import Protocol 4 5 from langchain_core.documents import Document 6 7 8 class Reranker(Protocol): 9 """Protocol for document reranking backends.""" 10 11 def rerank( 12 self, query: str, documents: list[tuple[Document, float]] 13 ) -> list[tuple[Document, float]]: 14 """Rerank documents based on relevance to the query. 15 16 Parameters 17 ---------- 18 query 19 User's search query 20 documents 21 List of (Document, score) tuples from initial retrieval 22 23 Returns 24 ------- 25 List of (Document, score) tuples reordered by relevance with new scores 26 """ 27 ...