trulens.core.guardrails.base¶
trulens.core.guardrails.base
¶
Classes¶
context_filter
¶
Provides a decorator to filter contexts based on a given feedback and threshold.
Parameters: feedback (Feedback): The feedback object to use for filtering. threshold (float): The minimum feedback value required for a context to be included. keyword_for_prompt (str): Keyword argument to decorator to use for prompt.
Example:
```python
feedback = Feedback(provider.context_relevance, name="Context Relevance")
class RAG_from_scratch:
...
@context_filter(feedback, 0.5, "query")
def retrieve(self, *, query: str) -> list:
results = vector_store.query(
query_texts=query,
n_results=3
)
return [doc for sublist in results['documents'] for doc in sublist]
...
```