/ src / retrievers / protocol.py
protocol.py
 1  from __future__ import annotations
 2  
 3  """Protocol for retriever implementations."""
 4  
 5  from typing import Any, Protocol
 6  
 7  from langchain_core.documents import Document
 8  
 9  
10  class Retriever(Protocol):
11      """Protocol for document retriever implementations.
12  
13      Any class implementing these methods can retrieve documents using
14      different strategies (similarity search, MMR, etc.).
15      """
16  
17      def retrieve(self, query: str) -> list[Document]:
18          """Retrieve relevant documents for a query."""
19          ...
20  
21      def retrieve_with_scores(self, query: str) -> list[tuple[Document, float]]:
22          """Retrieve documents with similarity scores."""
23          ...
24  
25      def set_filter(self, filter: Any | None) -> None:
26          """Set the metadata filter for retrieval.
27  
28          Parameters
29          ----------
30          filter
31              Optional metadata filter (vector store specific).
32          """
33          ...
34