trulens.providers.cortex - πŸ¦‘ TruLens

trulens.providers.cortex [ΒΆ](/content/reference/trulens/providers/cortex/#trulensproviderscortex "Permanent link"/index.html)

``trulens.providers.cortex [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex "Permanent link"/index.html)

Additional Dependency Required

To use this module, you must have the trulens-providers-cortex package installed.

pip install trulens-providers-cortex

Classes [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex-classes "Permanent link"/index.html)

``Cortex [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex "Permanent link"/index.html)

Bases: LLMProvider

Attributes [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex-attributes "Permanent link"/index.html)
``tru_class_infoinstance-attribute[ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.tru_class_info "Permanent link"/index.html)
tru_class_info: Class

Class information of this pydantic object for use in deserialization.

Using this odd key to not pollute attribute names in whatever class we mix this into. Should be the same as CLASS_INFO.

``retry_timeoutinstance-attribute[ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.retry_timeout "Permanent link"/index.html)
retry_timeout: Optional[float]

Snowflake's Cortex COMPLETE endpoint. Defaults to llama3.3-70b.

Reference: https://docs.snowflake.com/en/sql-reference/functions/complete-snowflake-cortex

Example

Connecting with user/passwordConnecting with private keyConnecting with a private key file

connection_parameters = {
    "account": <account>,
    "user": <user>,
    "password": <password>,
    "role": <role>,
    "database": <database>,
    "schema": <schema>,
    "warehouse": <warehouse>
}
snowpark_session = Session.builder.configs(connection_parameters).create()
provider = Cortex(snowpark_session=snowpark_session)
connection_parameters = {
    "account": <account>,
    "user": <user>,
    "private_key": <private_key>,
    "role": <role>,
    "database": <database>,
    "schema": <schema>,
    "warehouse": <warehouse>
}
snowpark_session = Session.builder.configs(connection_parameters).create()
provider = Cortex(snowpark_session=snowpark_session)
connection_parameters = {
    "account": <account>,
    "user": <user>,
    "private_key_file": <private_key_file>,
    "private_key_file_pwd": <private_key_file_pwd>,
    "role": <role>,
    "database": <database>,
    "schema": <schema>,
    "warehouse": <warehouse>
}
snowpark_session = Session.builder.configs(connection_parameters).create()
provider = Cortex(snowpark_session=snowpark_session)
PARAMETER DESCRIPTION
snowpark_session Snowflake session.
TYPE:Session
model_engine Model engine to use. Defaults to snowflake-arctic.
TYPE:str
Functions [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex-functions "Permanent link"/index.html)
``__repr__ [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.__repr__ "Permanent link"/index.html)
__repr__() -> str

Safe repr that handles circular references.

Pydantic's default __repr__ does not guard against circular references among model instances, which leads to RecursionError (see GitHub issue #1862). This override uses the same formatted_objects context-variable that __rich_repr__ uses so that already-visited objects are replaced with a short placeholder instead of recursing infinitely.

``__rich_repr__ [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.__rich_repr__ "Permanent link"/index.html)
__rich_repr__() -> Result

Requirement for pretty printing using the rich package.

``loadstaticmethod[ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.load "Permanent link"/index.html)
load(obj, *args, **kwargs)

Deserialize/load this object using the class information in tru_class_info to lookup the actual class that will do the deserialization.

``model_validateclassmethod[ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.model_validate "Permanent link"/index.html)
model_validate(*args, **kwargs) -> Any

Deserialized a jsonized version of the app into the instance of the class it was serialized from.

Note

This process uses extra information stored in the jsonized object and handled by [WithClassInfo](/content/reference/trulens/core/utils/pyschema/#trulens.core.utils.pyschema.WithClassInfo " WithClassInfo"/index.html).

``generate_score [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.generate_score "Permanent link"/index.html)
generate_score(
    system_prompt: str,
    user_prompt: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 10,
    temperature: float = 0.0,
) -> float

Base method to generate a score normalized to 0 to 1, used for evaluation.

PARAMETER DESCRIPTION
system_prompt A pre-formatted system prompt.
TYPE:str
user_prompt An optional user prompt.
TYPE:Optional[str]DEFAULT:None
min_score_val The minimum score value.
TYPE:intDEFAULT:0
max_score_val The maximum score value.
TYPE:intDEFAULT:10
temperature The temperature for the LLM response.
TYPE:floatDEFAULT:0.0
RETURNS DESCRIPTION
float The normalized score on a 0-1 scale.
``generate_score_and_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.generate_score_and_reasons "Permanent link"/index.html)
generate_score_and_reasons(
    system_prompt: str,
    user_prompt: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 10,
    temperature: float = 0.0,
) -> Tuple[float, Dict]

Base method to generate a score and reason, used for evaluation.

PARAMETER DESCRIPTION
system_prompt A pre-formatted system prompt.
TYPE:str
user_prompt An optional user prompt. Defaults to None.
TYPE:Optional[str]DEFAULT:None
min_score_val The minimum score value.
TYPE:intDEFAULT:0
max_score_val The maximum score value.
TYPE:intDEFAULT:10
temperature The temperature for the LLM response.
TYPE:floatDEFAULT:0.0
RETURNS DESCRIPTION
Tuple[float, Dict] Tuple[float, Dict]: A tuple containing the normalized score on a 0-1 scale and
reason metadata dictionary.
``context_relevance [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.context_relevance "Permanent link"/index.html)
context_relevance(
    question: str,
    context: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    examples: Optional[List[str]] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> float

Uses chat completion model. A function that completes a template to check the relevance of the context to the question.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.context_relevance,
    name="Context Relevance",
    criteria=criteria,
    additional_instructions=additional_instructions,
    examples=examples,
    selectors={
        "question": Selector.select_record_input(),
        "context": Selector.select_context(
            collect_list=False
        ),
    },
    agg=np.mean,
)
PARAMETER DESCRIPTION
question A question being asked.
TYPE:str
context Context related to the question.
TYPE:str
criteria If provided, overrides the default criteria for evaluation. Defaults to None.
TYPE:Optional[str]DEFAULT:None
additional_instructions If provided, adds instructions to default criteria for the judge to follow. Defaults to None.
TYPE:Optional[str]DEFAULT:None
examples Optional few-shot examples to guide the evaluation. Defaults to None.
TYPE:Optional[List[str]]DEFAULT:None
min_score_val The minimum score value. Defaults to 0.
TYPE:intDEFAULT:0
max_score_val The maximum score value. Defaults to 3.
TYPE:intDEFAULT:3
temperature The temperature for the LLM response, which might have impact on the confidence level of the evaluation. Defaults to 0.0.
TYPE:floatDEFAULT:0.0
RETURNS DESCRIPTION
float A value between 0.0 (not relevant) and 1.0 (relevant).
TYPE:float
``context_relevance_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.context_relevance_with_cot_reasons "Permanent link"/index.html)
context_relevance_with_cot_reasons(
    question: str,
    context: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    examples: Optional[List[str]] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> Tuple[float, Dict]

Uses chat completion model. A function that completes a template to check the relevance of the context to the question. Also uses chain of thought methodology and emits the reasons.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.context_relevance_with_cot_reasons,
    name="Context Relevance",
    criteria=criteria,
    additional_instructions=additional_instructions,
    examples=examples,
    selectors={
        "question": Selector.select_record_input(),
        "context": Selector.select_context(
            collect_list=False
        ),
    },
    agg=np.mean,
)
RETURNS DESCRIPTION
float A value between 0 and 1. 0 being "not relevant" and 1 being "relevant".
TYPE:Tuple[float, Dict]
``relevance [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.relevance "Permanent link"/index.html)
relevance(
    prompt: str,
    response: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    examples: Optional[List[str]] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> float

Uses chat completion model. A function that completes a template to check the relevance of the response to a prompt.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.relevance,
    name="Answer Relevance",
    criteria=criteria,
    additional_instructions=additional_instructions,
    examples=examples,
    selectors={
        "prompt": Selector.select_record_input(),
        "response": Selector.select_record_output(),
    },
)
PARAMETER DESCRIPTION
prompt A text prompt to an agent.
TYPE:str
response The agent's response to the prompt.
TYPE:str
criteria If provided, overrides the default criteria for evaluation. Defaults to None.
TYPE:Optional[str]DEFAULT:None
additional_instructions If provided, adds instructions to default criteria for the judge to follow. Defaults to None.
TYPE:Optional[str]DEFAULT:None
examples Optional few-shot examples to guide the evaluation. Defaults to None.
TYPE:Optional[List[str]]DEFAULT:None
min_score_val The minimum score value used by the LLM before normalization. Defaults to 0.
TYPE:intDEFAULT:0
max_score_val The maximum score value used by the LLM before normalization. Defaults to 3.
TYPE:intDEFAULT:3
temperature The temperature for the LLM response, which might have impact on the confidence level of the evaluation. Defaults to 0.0.
TYPE:floatDEFAULT:0.0
RETURNS DESCRIPTION
float A value between 0 and 1. 0 being "not relevant" and 1 being "relevant".
TYPE:float
``relevance_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.relevance_with_cot_reasons "Permanent link"/index.html)
relevance_with_cot_reasons(
    prompt: str,
    response: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    examples: Optional[List[str]] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> Tuple[float, Dict]

Uses chat completion Model. A function that completes a template to check the relevance of the response to a prompt. Also uses chain of thought methodology and emits the reasons.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.relevance_with_cot_reasons,
    name="Answer Relevance",
    criteria=criteria,
    additional_instructions=additional_instructions,
    examples=examples,
    selectors={
        "prompt": Selector.select_record_input(),
        "response": Selector.select_record_output(),
    },
)
RETURNS DESCRIPTION
float A value between 0 and 1. 0 being "not relevant" and 1 being
"relevant".
TYPE:Tuple[float, Dict]
``sentiment [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.sentiment "Permanent link"/index.html)
sentiment(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    examples: Optional[List[str]] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> float

Uses chat completion model. A function that completes a template to check the sentiment of some text.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.sentiment,
    name="Sentiment",
    criteria=criteria,
    additional_instructions=additional_instructions,
    examples=examples,
    selectors={
        "text": Selector.select_record_output(),
    },
)
PARAMETER DESCRIPTION
text The text to evaluate sentiment of.
TYPE:str
criteria If provided, overrides the default criteria for evaluation. Defaults to None.
TYPE:Optional[str]DEFAULT:None
additional_instructions If provided, adds instructions to default criteria for the judge to follow.
TYPE:Optional[str]DEFAULT:None
examples Optional few-shot examples to guide the evaluation. Defaults to None.
TYPE:Optional[List[str]]DEFAULT:None
min_score_val The minimum score value used by the LLM before normalization. Defaults to 0.
TYPE:intDEFAULT:0
max_score_val The maximum score value used by the LLM before normalization. Defaults to 3.
TYPE:intDEFAULT:3
temperature The temperature for the LLM response, which might have impact on the confidence level of the evaluation. Defaults to 0.0.
TYPE:floatDEFAULT:0.0
RETURNS DESCRIPTION
float A value between 0 and 1. 0 being "negative sentiment" and 1
being "positive sentiment".
TYPE:float
``sentiment_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.sentiment_with_cot_reasons "Permanent link"/index.html)
sentiment_with_cot_reasons(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    examples: Optional[List[str]] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> Tuple[float, Dict]

Uses chat completion model. A function that completes a template to check the sentiment of some text. Also uses chain of thought methodology and emits the reasons.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.sentiment_with_cot_reasons,
    name="Sentiment",
    criteria=criteria,
    additional_instructions=additional_instructions,
    examples=examples,
    selectors={
        "text": Selector.select_record_output(),
    },
)
PARAMETER DESCRIPTION
text Text to evaluate.
TYPE:str
criteria If provided, overrides the default criteria for evaluation. Defaults to None.
TYPE:Optional[str]DEFAULT:None
additional_instructions If provided, adds instructions to default criteria for the judge to follow.
TYPE:Optional[str]DEFAULT:None
examples Optional few-shot examples to guide the evaluation. Defaults to None.
TYPE:Optional[List[str]]DEFAULT:None
min_score_val The minimum score value used by the LLM before normalization. Defaults to 0.
TYPE:intDEFAULT:0
max_score_val The maximum score value used by the LLM before normalization. Defaults to 3.
TYPE:intDEFAULT:3
temperature The temperature for the LLM response, which might have impact on the confidence level of the evaluation. Defaults to 0.0.
TYPE:floatDEFAULT:0.0
RETURNS DESCRIPTION
float A value between 0.0 (negative sentiment) and 1.0 (positive sentiment).
TYPE:Tuple[float, Dict]
``model_agreement [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.model_agreement "Permanent link"/index.html)
model_agreement(prompt: str, response: str) -> float

Uses chat completion model. A function that gives a chat completion model the same prompt and gets a response, encouraging truthfulness. A second template is given to the model with a prompt that the original response is correct, and measures whether previous chat completion response is similar.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.model_agreement,
    name="Model Agreement",
    selectors={
        "prompt": Selector.select_record_input(),
        "response": Selector.select_record_output(),
    },
)
PARAMETER DESCRIPTION
prompt A text prompt to an agent.
TYPE:str
response The agent's response to the prompt.
TYPE:str
RETURNS DESCRIPTION
float A value between 0.0 (not in agreement) and 1.0 (in agreement).
TYPE:float
``conciseness [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.conciseness "Permanent link"/index.html)
conciseness(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> float

Uses chat completion model. A function that completes a template to check the conciseness of some text. Prompt credit to LangChain Eval.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.conciseness,
    name="Conciseness",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)
PARAMETER DESCRIPTION
text The text to evaluate the conciseness of.
TYPE:str
criteria If provided, overrides the default criteria for evaluation. Defaults to None.
TYPE:Optional[str]DEFAULT:None
additional_instructions If provided, adds instructions to default criteria for the judge to follow. Defaults to None.
TYPE:Optional[str]DEFAULT:None
min_score_val The minimum score value used by the LLM before normalization. Defaults to 0.
TYPE:intDEFAULT:0
max_score_val The maximum score value used by the LLM before normalization. Defaults to 3.
TYPE:intDEFAULT:3
temperature The temperature for the LLM response, which might have impact on the confidence level of the evaluation. Defaults to 0.0.
TYPE:floatDEFAULT:0.0
RETURNS DESCRIPTION
float A value between 0.0 (not concise) and 1.0 (concise).
TYPE:float
``conciseness_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.conciseness_with_cot_reasons "Permanent link"/index.html)
conciseness_with_cot_reasons(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> Tuple[float, Dict]

Uses chat completion model. A function that completes a template to check the conciseness of some text. Prompt credit to LangChain Eval.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.conciseness_with_cot_reasons,
    name="Conciseness",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)

Args: text (str): The text to evaluate the conciseness of. criteria (Optional[str]): If provided, overrides the default criteria for evaluation. Defaults to None. additional_instructions (Optional[str]): If provided, adds instructions to default criteria for the judge to follow. Defaults to None. min_score_val (int): The minimum score value used by the LLM before normalization. Defaults to 0. max_score_val (int): The maximum score value used by the LLM before normalization. Defaults to 3. temperature (float): The temperature for the LLM response, which might have impact on the confidence level of the evaluation. Defaults to 0.0.

RETURNS DESCRIPTION
Tuple[float, Dict] Tuple[float, Dict]: A tuple containing a value between 0.0 (not concise) and 1.0 (concise) and a dictionary containing the reasons for the evaluation.
``correctness [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.correctness "Permanent link"/index.html)
correctness(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> float

Uses chat completion model. A function that completes a template to check the correctness of some text. Prompt credit to LangChain Eval.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.correctness,
    name="Correctness",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)
PARAMETER DESCRIPTION
text A prompt to an agent.
TYPE:str
criteria If provided, overrides the default criteria for evaluation. Defaults to None.
TYPE:Optional[str]DEFAULT:None
additional_instructions If provided, adds instructions to default criteria for the judge to follow. Defaults to None.
TYPE:Optional[str]DEFAULT:None
min_score_val The minimum score value used by the LLM before normalization. Defaults to 0.
TYPE:intDEFAULT:0
max_score_val The maximum score value used by the LLM before normalization. Defaults to 3.
TYPE:intDEFAULT:3
temperature The temperature for the LLM response, which might have impact on the confidence level of the evaluation. Defaults to 0.0.
TYPE:floatDEFAULT:0.0
RETURNS DESCRIPTION
float A value between 0.0 (not correct) and 1.0 (correct).
TYPE:float
``correctness_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.correctness_with_cot_reasons "Permanent link"/index.html)
correctness_with_cot_reasons(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> Tuple[float, Dict]

Uses chat completion model. A function that completes a template to check the correctness of some text. Prompt credit to LangChain Eval. Also uses chain of thought methodology and emits the reasons.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.correctness_with_cot_reasons,
    name="Correctness",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)
PARAMETER DESCRIPTION
text Text to evaluate.
TYPE:str
criteria If provided, overrides the default criteria for evaluation. Defaults to None.
TYPE:Optional[str]DEFAULT:None
additional_instructions If provided, adds instructions to default criteria for the judge to follow. Defaults to None.
TYPE:Optional[str]DEFAULT:None
min_score_val The minimum score value used by the LLM before normalization. Defaults to 0.
TYPE:intDEFAULT:0
max_score_val The maximum score value used by the LLM before normalization. Defaults to 3.
TYPE:intDEFAULT:3
temperature The temperature for the LLM response, which might have impact on the confidence level of the evaluation. Defaults to 0.0.
TYPE:floatDEFAULT:0.0
RETURNS DESCRIPTION
Tuple[float, Dict] Tuple[float, Dict]: A tuple containing a value between 0.0 (not correct) and 1.0 (correct) and a dictionary containing the reasons for the evaluation.
``coherence [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.coherence "Permanent link"/index.html)
coherence(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> float

Uses chat completion model. A function that completes a template to check the coherence of some text. Prompt credit to LangChain Eval.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.coherence,
    name="Coherence",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)
PARAMETER DESCRIPTION
text The text to evaluate.
TYPE:str
criteria If provided, overrides the default criteria for evaluation. Defaults to None.
TYPE:Optional[str]DEFAULT:None
additional_instructions If provided, adds instructions to default criteria for the judge to follow. Defaults to None.
TYPE:Optional[str]DEFAULT:None
min_score_val The minimum score value used by the LLM before normalization. Defaults to 0.
TYPE:intDEFAULT:0
max_score_val The maximum score value used by the LLM before normalization. Defaults to 3.
TYPE:intDEFAULT:3
temperature The temperature for the LLM response, which might have impact on the confidence level of the evaluation. Defaults to 0.0.
TYPE:floatDEFAULT:0.0
RETURNS DESCRIPTION
float A value between 0.0 (not coherent) and 1.0 (coherent).
TYPE:float
``coherence_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.coherence_with_cot_reasons "Permanent link"/index.html)
coherence_with_cot_reasons(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> Tuple[float, Dict]

Uses chat completion model. A function that completes a template to check the coherence of some text. Prompt credit to LangChain Eval. Also uses chain of thought methodology and emits the reasons.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.coherence_with_cot_reasons,
    name="Coherence",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)
RETURNS DESCRIPTION
Tuple[float, Dict] Tuple[float, Dict]: A tuple containing a value between 0.0 (not coherent) and 1.0 (coherent) and a dictionary containing the reasons for the evaluation.
``harmfulness [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.harmfulness "Permanent link"/index.html)
harmfulness(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> float

Uses chat completion model. A function that completes a template to check the harmfulness of some text. Prompt credit to LangChain Eval.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.harmfulness,
    name="Harmfulness",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)
PARAMETER DESCRIPTION
text The text to evaluate.
TYPE:str
criteria If provided, overrides the default criteria for evaluation. Defaults to None.
TYPE:Optional[str]DEFAULT:None
min_score_val The minimum score value used by the LLM before normalization. Defaults to 0.
TYPE:intDEFAULT:0
additional_instructions If provided, adds instructions to default criteria for the judge to follow. Defaults to None.
TYPE:Optional[str]DEFAULT:None
max_score_val The maximum score value used by the LLM before normalization. Defaults to 3.
TYPE:intDEFAULT:3
temperature The temperature for the LLM response, which might have impact on the confidence level of the evaluation. Defaults to 0.0.
TYPE:floatDEFAULT:0.0
RETURNS DESCRIPTION
float A value between 0.0 (not harmful) and 1.0 (harmful)".
TYPE:float
``harmfulness_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.harmfulness_with_cot_reasons "Permanent link"/index.html)
harmfulness_with_cot_reasons(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> Tuple[float, Dict]

Uses chat completion model. A function that completes a template to check the harmfulness of some text. Prompt credit to LangChain Eval. Also uses chain of thought methodology and emits the reasons.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.harmfulness_with_cot_reasons,
    name="Harmfulness",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)
RETURNS DESCRIPTION
Tuple[float, Dict] Tuple[float, Dict]: A tuple containing a value between 0.0 (not harmful) and 1.0 (harmful) and a dictionary containing the reasons for the evaluation.
``maliciousness [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.maliciousness "Permanent link"/index.html)
maliciousness(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> float

Uses chat completion model. A function that completes a template to check the maliciousness of some text. Prompt credit to LangChain Eval.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.maliciousness,
    name="Maliciousness",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)
RETURNS DESCRIPTION
float A value between 0.0 (not malicious) and 1.0 (malicious).
TYPE:float
``maliciousness_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.maliciousness_with_cot_reasons "Permanent link"/index.html)
maliciousness_with_cot_reasons(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> Tuple[float, Dict]

Uses chat completion model. A function that completes a template to check the maliciousness of some text. Prompt credit to LangChain Eval. Also uses chain of thought methodology and emits the reasons.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.maliciousness_with_cot_reasons,
    name="Maliciousness",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)
RETURNS DESCRIPTION
Tuple[float, Dict] Tuple[float, Dict]: A tuple containing a value between 0.0 (not malicious) and 1.0 (malicious) and a dictionary containing the reasons for the evaluation.
``helpfulness [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.helpfulness "Permanent link"/index.html)
helpfulness(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> float

Uses chat completion model. A function that completes a template to check the helpfulness of some text. Prompt credit to LangChain Eval.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.helpfulness,
    name="Helpfulness",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)
RETURNS DESCRIPTION
float A value between 0.0 (not helpful) and 1.0 (helpful).
TYPE:float
``helpfulness_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.helpfulness_with_cot_reasons "Permanent link"/index.html)
helpfulness_with_cot_reasons(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> Tuple[float, Dict]

Uses chat completion model. A function that completes a template to check the helpfulness of some text. Prompt credit to LangChain Eval. Also uses chain of thought methodology and emits the reasons.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.helpfulness_with_cot_reasons,
    name="Helpfulness",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)
RETURNS DESCRIPTION
Tuple[float, Dict] Tuple[float, Dict]: A tuple containing a value between 0.0 (not helpful) and 1.0 (helpful) and a dictionary containing the reasons for the evaluation.
``controversiality [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.controversiality "Permanent link"/index.html)
controversiality(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> float

Uses chat completion model. A function that completes a template to check the controversiality of some text. Prompt credit to Langchain Eval.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.controversiality,
    name="Controversiality",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)
RETURNS DESCRIPTION
float A value between 0.0 (not controversial) and 1.0
(controversial).
TYPE:float
``controversiality_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.controversiality_with_cot_reasons "Permanent link"/index.html)
controversiality_with_cot_reasons(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> Tuple[float, Dict]

Uses chat completion model. A function that completes a template to check the controversiality of some text. Prompt credit to Langchain Eval. Also uses chain of thought methodology and emits the reasons.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.controversiality_with_cot_reasons,
    name="Controversiality",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)
RETURNS DESCRIPTION
Tuple[float, Dict] Tuple[float, Dict]: A tuple containing a value between 0.0 (not controversial) and 1.0 (controversial) and a dictionary containing the reasons for the evaluation.
``misogyny [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.misogyny "Permanent link"/index.html)
misogyny(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> float

Uses chat completion model. A function that completes a template to check the misogyny of some text. Prompt credit to LangChain Eval.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.misogyny,
    name="Misogyny",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)
RETURNS DESCRIPTION
float A value between 0.0 (not misogynistic) and 1.0 (misogynistic).
TYPE:float
``misogyny_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.misogyny_with_cot_reasons "Permanent link"/index.html)
misogyny_with_cot_reasons(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> Tuple[float, Dict]

Uses chat completion model. A function that completes a template to check the misogyny of some text. Prompt credit to LangChain Eval. Also uses chain of thought methodology and emits the reasons.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.misogyny_with_cot_reasons,
    name="Misogyny",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)
RETURNS DESCRIPTION
Tuple[float, Dict] Tuple[float, Dict]: A tuple containing a value between 0.0 (not misogynistic) and 1.0 (misogynistic) and a dictionary containing the reasons for the evaluation.
``criminality [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.criminality "Permanent link"/index.html)
criminality(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> float

Uses chat completion model. A function that completes a template to check the criminality of some text. Prompt credit to LangChain Eval.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.criminality,
    name="Criminality",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)
RETURNS DESCRIPTION
float A value between 0.0 (not criminal) and 1.0 (criminal).
TYPE:float
``criminality_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.criminality_with_cot_reasons "Permanent link"/index.html)
criminality_with_cot_reasons(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> Tuple[float, Dict]

Uses chat completion model. A function that completes a template to check the criminality of some text. Prompt credit to LangChain Eval. Also uses chain of thought methodology and emits the reasons.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.criminality_with_cot_reasons,
    name="Criminality",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)
RETURNS DESCRIPTION
Tuple[float, Dict] Tuple[float, Dict]: A tuple containing a value between 0.0 (not criminal) and 1.0 (criminal) and a dictionary containing the reasons for the evaluation.
``insensitivity [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.insensitivity "Permanent link"/index.html)
insensitivity(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> float

Uses chat completion model. A function that completes a template to check the insensitivity of some text. Prompt credit to LangChain Eval.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.insensitivity,
    name="Insensitivity",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)
RETURNS DESCRIPTION
float A value between 0.0 (not insensitive) and 1.0 (insensitive).
TYPE:float
``insensitivity_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.insensitivity_with_cot_reasons "Permanent link"/index.html)
insensitivity_with_cot_reasons(
    text: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> Tuple[float, Dict]

Uses chat completion model. A function that completes a template to check the insensitivity of some text. Prompt credit to LangChain Eval. Also uses chain of thought methodology and emits the reasons.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.insensitivity_with_cot_reasons,
    name="Insensitivity",
    criteria=criteria,
    additional_instructions=additional_instructions,
    selectors={
        "text": Selector.select_record_output(),
    },
)
RETURNS DESCRIPTION
Tuple[float, Dict] Tuple[float, Dict]: A tuple containing a value between 0.0 (not insensitive) and 1.0 (insensitive) and a dictionary containing the reasons for the evaluation.
``comprehensiveness_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.comprehensiveness_with_cot_reasons "Permanent link"/index.html)
comprehensiveness_with_cot_reasons(
    source: str,
    summary: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> Tuple[float, Dict]

Uses chat completion model. A function that tries to distill main points and compares a summary against those main points. This feedback function only has a chain of thought implementation as it is extremely important in function assessment.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.comprehensiveness_with_cot_reasons,
    name="Comprehensiveness",
    selectors={
        "source": Selector.select_record_input(),
        "summary": Selector.select_record_output(),
    },
)
PARAMETER DESCRIPTION
source Text corresponding to source material.
TYPE:str
summary Text corresponding to a summary.
TYPE:str
criteria If provided, overrides the default criteria for evaluation. Defaults to None.
TYPE:Optional[str]DEFAULT:None
additional_instructions If provided, adds instructions to default criteria for the judge to follow.
TYPE:Optional[str]DEFAULT:None
min_score_val The minimum score value used by the LLM before normalization. Defaults to 0.
TYPE:intDEFAULT:0
max_score_val The maximum score value used by the LLM before normalization. Defaults to 3.
TYPE:intDEFAULT:3
temperature The temperature for the LLM response, which might have impact on the confidence level of the evaluation. Defaults to 0.0.
TYPE:floatDEFAULT:0.0
RETURNS DESCRIPTION
Tuple[float, Dict] Tuple[float, Dict]: A tuple containing a value between 0.0 (not comprehensive) and 1.0 (comprehensive) and a dictionary containing the reasons for the evaluation.
``summarization_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.summarization_with_cot_reasons "Permanent link"/index.html)
summarization_with_cot_reasons(
    source: str, summary: str
) -> Tuple[float, Dict]

Summarization is deprecated in place of comprehensiveness. This function is no longer implemented.

``stereotypes [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.stereotypes "Permanent link"/index.html)
stereotypes(
    prompt: str,
    response: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> float

Uses chat completion model. A function that completes a template to check adding assumed stereotypes in the response when not present in the prompt.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.stereotypes,
    name="Stereotypes",
    selectors={
        "prompt": Selector.select_record_input(),
        "response": Selector.select_record_output(),
    },
)
PARAMETER DESCRIPTION
prompt A text prompt to an agent.
TYPE:str
response The agent's response to the prompt.
TYPE:str
criteria If provided, overrides the default criteria for evaluation. Defaults to None.
TYPE:Optional[str]DEFAULT:None
additional_instructions If provided, adds instructions to default criteria for the judge to follow.
TYPE:Optional[str]DEFAULT:None
min_score_val The minimum score value used by the LLM before normalization. Defaults to 0.
TYPE:intDEFAULT:0
max_score_val The maximum score value used by the LLM before normalization. Defaults to 3.
TYPE:intDEFAULT:3
temperature The temperature for the LLM response, which might have impact on the confidence level of the evaluation. Defaults to 0.0.
TYPE:floatDEFAULT:0.0
RETURNS DESCRIPTION
float A value between 0.0 (no stereotypes assumed) and 1.0 (stereotypes assumed).
TYPE:float
``stereotypes_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.stereotypes_with_cot_reasons "Permanent link"/index.html)
stereotypes_with_cot_reasons(
    prompt: str,
    response: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> Tuple[float, Dict]

Uses chat completion model. A function that completes a template to check adding assumed stereotypes in the response when not present in the prompt. Also uses chain of thought methodology and emits the reasons.

Example

from trulens.core import Metric, Selector
feedback = Metric(
    implementation=provider.stereotypes_with_cot_reasons,
    name="Stereotypes",
    selectors={
        "prompt": Selector.select_record_input(),
        "response": Selector.select_record_output(),
    },
)
RETURNS DESCRIPTION
Tuple[float, Dict] Tuple[float, Dict]: A tuple containing a value between 0.0 (no stereotypes assumed) and 1.0 (stereotypes assumed) and a dictionary containing the reasons for the evaluation.
``groundedness_measure_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.groundedness_measure_with_cot_reasons "Permanent link"/index.html)
groundedness_measure_with_cot_reasons(
    source: str,
    statement: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    examples: Optional[str] = None,
    groundedness_configs: Optional[\
        GroundednessConfigs\
    ] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> Tuple[float, dict]

A measure to track if the source material supports each sentence in the statement using an LLM provider.

The statement will first be split by a tokenizer into its component sentences.

Then, trivial statements are eliminated so as to not dilute the evaluation. Note that if all statements are filtered out as trivial, returns 0.0 with a reason indicating no non-trivial statements were found.

The LLM will process each statement, using chain of thought methodology to emit the reasons.

Abstentions will be considered as grounded.

Example

from trulens.core import Metric, Selector
from trulens.providers.openai import OpenAI

provider = OpenAI()

f_groundedness = Metric(
    implementation=provider.groundedness_measure_with_cot_reasons,
    name="Groundedness",
    selectors={
        "source": Selector.select_context(
            collect_list=True
        ),
        "statement": Selector.select_record_output(),
    },
)

To further explain how the function works under the hood, consider the statement:

"Hi. I'm here to help. The university of Washington is a public research university. UW's connections to major corporations in Seattle contribute to its reputation as a hub for innovation and technology"

The function will split the statement into its component sentences:

  1. "Hi."
  2. "I'm here to help."
  3. "The university of Washington is a public research university."
  4. "UW's connections to major corporations in Seattle contribute to its reputation as a hub for innovation and technology"

Next, trivial statements are removed, leaving only:

  1. "The university of Washington is a public research university."
  2. "UW's connections to major corporations in Seattle contribute to its reputation as a hub for innovation and technology"

The LLM will then process the statement, to assess the groundedness of the statement.

For the sake of this example, the LLM will grade the groundedness of one statement as 10, and the other as 0.

Then, the scores are normalized, and averaged to give a final groundedness score of 0.5.

PARAMETER DESCRIPTION
source The source that should support the statement.
TYPE:str
statement The statement to check groundedness.
TYPE:str
criteria If provided, overrides the default criteria for evaluation. Defaults to None.
TYPE:Optional[str]DEFAULT:None
additional_instructions If provided, adds instructions to default criteria for the judge to follow.
TYPE:Optional[str]DEFAULT:None
examples Optional examples to guide the evaluation. Defaults to None.
TYPE:Optional[str]DEFAULT:None
groundedness_configs Configuration for groundedness evaluation. Defaults to None.
TYPE:Optional[GroundednessConfigs]DEFAULT:None
min_score_val The minimum score value used by the LLM before normalization. Defaults to 0.
TYPE:intDEFAULT:0
max_score_val The maximum score value used by the LLM before normalization. Defaults to 3.
TYPE:intDEFAULT:3
temperature The temperature for the LLM response, which might have impact on the confidence level of the evaluation. Defaults to 0.0.
TYPE:floatDEFAULT:0.0
RETURNS DESCRIPTION
Tuple[float, dict] Tuple[float, dict]: A tuple containing a value between 0.0 (not grounded) and 1.0 (grounded) and a dictionary containing the reasons for the evaluation.
``qs_relevance [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.qs_relevance "Permanent link"/index.html)
qs_relevance(*args, **kwargs)

Deprecated. Use relevance instead.

``qs_relevance_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.qs_relevance_with_cot_reasons "Permanent link"/index.html)
qs_relevance_with_cot_reasons(*args, **kwargs)

Deprecated. Use relevance_with_cot_reasons instead.

``groundedness_measure_with_cot_reasons_consider_answerability [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.groundedness_measure_with_cot_reasons_consider_answerability "Permanent link"/index.html)
groundedness_measure_with_cot_reasons_consider_answerability(
    source: str,
    statement: str,
    question: str,
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    examples: Optional[List[str]] = None,
    groundedness_configs: Optional[\
        GroundednessConfigs\
    ] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    **kwargs
) -> Tuple[float, dict]

A measure to track if the source material supports each sentence in the statement using an LLM provider.

The statement will first be split by a tokenizer into its component sentences.

The LLM will process each statement, using chain of thought methodology to emit the reasons.

In the case of abstentions, such as 'I do not know', the LLM will be asked to consider the answerability of the question given the source material.

If the question is considered answerable, abstentions will be considered as not grounded and punished with low scores. Otherwise, unanswerable abstentions will be considered grounded.

Example

from trulens.core import Metric, Selector
from trulens.providers.openai import OpenAI

provider = OpenAI()

f_groundedness = Metric(
    implementation=provider.groundedness_measure_with_cot_reasons_consider_answerability,
    name="Groundedness",
    selectors={
        "source": Selector.select_context(
            collect_list=True
        ),
        "statement": Selector.select_record_output(),
        "question": Selector.select_record_input(),
    },
)
PARAMETER DESCRIPTION
source The source that should support the statement.
TYPE:str
statement The statement to check groundedness.
TYPE:str
question The question to check answerability.
TYPE:str
criteria If provided, overrides the default criteria for evaluation. Defaults to None.
TYPE:Optional[str]DEFAULT:None
additional_instructions If provided, adds instructions to default criteria for the judge to follow.
TYPE:Optional[str]DEFAULT:None
examples Optional examples to guide the evaluation. Defaults to None.
TYPE:Optional[List[str]]DEFAULT:None
groundedness_configs Configuration for groundedness evaluation. Defaults to None.
TYPE:Optional[GroundednessConfigs]DEFAULT:None
min_score_val The minimum score value used by the LLM before normalization. Defaults to 0.
TYPE:intDEFAULT:0
max_score_val The maximum score value used by the LLM before normalization. Defaults to 3.
TYPE:intDEFAULT:3
temperature The temperature for the LLM response, which might have impact on the confidence level of the evaluation. Defaults to 0.0.
TYPE:floatDEFAULT:0.0
``logical_consistency_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.logical_consistency_with_cot_reasons "Permanent link"/index.html)
logical_consistency_with_cot_reasons(
    trace: Union[Trace, str],
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    examples: Optional[\
        List[Tuple[Dict[str, str], int]]\
    ] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    enable_trace_compression: bool = True,
    **kwargs
) -> Tuple[float, Dict]

Evaluate the quality of an agentic trace using a rubric focused on logical consistency and reasoning.

Example

from trulens.core import Metric, Selector
from trulens.providers.openai import OpenAI

provider = OpenAI()

f_logical_consistency = Metric(
    implementation=provider.logical_consistency_with_cot_reasons,
    name="Logical Consistency",
    selectors={
        "trace": Selector(trace_level=True),
    },
)
PARAMETER DESCRIPTION
trace The trace to evaluate (e.g., as a JSON string or formatted log).
TYPE:Union[Trace, str]
criteria If provided, overrides the default criteria for evaluation. Defaults to None.
TYPE:Optional[str]DEFAULT:None
additional_instructions If provided, adds instructions to default criteria for the judge to follow. Defaults to None.
TYPE:Optional[str]DEFAULT:None
examples Optional few-shot examples for evaluation. Defaults to None.
TYPE:Optional[List[Tuple[Dict[str, str], int]]]DEFAULT:None
min_score_val The minimum score value used by the LLM before normalization. Defaults to 0.
TYPE:intDEFAULT:0
max_score_val The maximum score value used by the LLM before normalization. Defaults to 3.
TYPE:intDEFAULT:3
temperature The temperature for the LLM response, which might have impact on the confidence level of the evaluation. Defaults to 0.0.
TYPE:floatDEFAULT:0.0
enable_trace_compression Whether to compress the trace data to reduce token usage. When True (default),
traces are compressed to preserve essential information while removing redundant data. Set to False to use
full, uncompressed traces. This parameter is only available for feedback functions that take 'trace' as input.
Defaults to True.
TYPE:boolDEFAULT:True

Returns: Tuple[float, Dict]: A tuple containing a value between 0.0 (no logical consistency) and 1.0 (complete logical consistency) and a dictionary containing the reasons for the evaluation.

``execution_efficiency_with_cot_reasons [ΒΆ](/content/reference/trulens/providers/cortex/#trulens.providers.cortex.Cortex.execution_efficiency_with_cot_reasons "Permanent link"/index.html)
execution_efficiency_with_cot_reasons(
    trace: Union[Trace, str],
    criteria: Optional[str] = None,
    additional_instructions: Optional[str] = None,
    examples: Optional[\
        List[Tuple[Dict[str, str], int]]\
    ] = None,
    min_score_val: int = 0,
    max_score_val: int = 3,
    temperature: float = 0.0,
    enable_trace_compression: bool = True,
    **kwargs
) -> Tuple[float, Dict]

Evaluate the quality of an agentic execution using a rubric focused on execution efficiency.

Example

from trulens.core import Metric, Selector
from trulens.providers.openai import OpenAI

provider = OpenAI()

f_execution_efficiency = Metric(
    implementation=provider.execution_efficiency_with_cot_reasons,
    name="Execution Efficiency",
    selectors={
        "trace": Selector(trace_level=True),
    },
)