Documentation for QueryRetriever
Class¶
Overview¶
The QueryRetriever
class is designed to facilitate the processing and retrieval of query items within a system. It encompasses multiple methods, each handling a specific aspect of query management including determining model classes, converting queries, extracting identifiers, obtaining storage metadata, and retrieving payload information.
Method Summaries¶
1. get_model_class
¶
- Functionality: Returns the model class for queries. Concrete classes should implement this method to return the actual class that implements the query model logic.
- Parameters: None.
- Usage: This method is used during the parsing of query dictionaries to determine the concrete model class for queries.
Example:
def get_model_class(self) -> Type[CustomQueryItem]:
return CustomQueryItem
2. _convert_query
¶
- Functionality: Converts a query object into an appropriate format for retrieval. It receives a query model instance (extending
QueryItemType
) and returns a representation suitable for search or storage backends. - Parameters:
query
: An instance ofQueryItemType
containing the query details, typically a Pydantic model with search parameters.- Usage: This method translates the query model into a format compatible with the underlying retrieval system.
Example:
def _convert_query(self, query: CustomQueryItem) -> str:
return query.search_text
3. _get_id
¶
- Functionality: Extracts a unique identifier from the query object. This method is key for converting a query into a string that uniquely identifies it.
- Parameters:
query
: A query object (e.g.,CustomQueryItem
) from which the unique identifier is derived.- Usage: This method generates a unique string identifier for a query instance.
Example:
def _get_id(self, query: CustomQueryItem) -> str:
return f"query_{query.search_text[:20]}"
4. _get_storage_metadata
¶
- Functionality: Extracts metadata from the query for storage purposes. This method returns a dictionary with metadata required for storage, obtained by processing the query object.
- Parameters:
query
: The query object or dictionary from which metadata is extracted.- Usage: It is used to extract storage-specific metadata from a given query.
Example:
def _get_storage_metadata(self, query: CustomQueryItem) -> Dict[str, Any]:
return query.model_dump()
5. _get_payload
¶
- Functionality: Extracts optional payload information from a query object, returning a dict of payload info if available or None.
- Parameters:
query
: A query object from which to extract payload info.- Usage: This method retrieves extra data from a query.
Example:
payload = retriever.get_payload(query)
if payload:
print(payload)