agentscope.service.retrieval.retrieval_from_list module
Retrieve service working with memory specially.
- agentscope.service.retrieval.retrieval_from_list.retrieve_from_list(query: Any, knowledge: Sequence, score_func: Callable[[Any, Any], float], top_k: int | None = None, embedding_model: ModelWrapperBase | None = None, preserve_order: bool = True) ServiceResponse [source]
Retrieve data in a list.
Memory retrieval with user-defined score function. The score function is expected to take the query and one of the element in ‘knowledge’ (a list). This function retrieves top-k elements in ‘knowledge’ with HIGHEST scores. If the ‘query’ is a dict but has no embedding, we use the embedding model to embed the query.
- Parameters:
query (Any) – A message to be retrieved.
knowledge (Sequence) – Data/knowledge to be retrieved from.
score_func (Callable[[Any, Any], float]) – User-defined function for comparing two messages.
top_k (int, defaults to None) – Maximum number of messages returned.
embedding_model (Optional[ModelWrapperBase], defaults to None) – A model to embed the query/message.
preserve_order (bool, defaults to True) – Whether to preserve the original order of the retrieved data. Defaults to True.
- Returns:
The top-k retrieved messages with HIGHEST scores.
- Return type:
ServiceResponse