Analyses the relevance of a generated answer to a given question, ensuring that the response appropriately addresses the query. The detector returns a relevancy score indicating how well the answer relates to the question which will be between 0 and 1. 0 if it is relevant and 1 if it is not relevant at all. The detector also provides a list of atomic facts and their relevancy scores, along with the response latency.

Example request:

import requests
import json
import os

url = "https://api.enkryptai.com/guardrails/relevancy"
payload = json.dumps({
"question": "What is CV Raman known for?",
"llm_answer": "C.V. Raman won the Nobel Prize for Physics in 1930 for his work on light scattering"
})

headers = {
    'Content-Type': 'application/json',
    'apikey': os.getenv('ENKRYPTAI_API_KEY')
}

response = requests.request("POST", url, headers=headers, data=payload)

formatted_response = json.dumps(json.loads(response.text), indent=4)
print(formatted_response)

Example response:

{
    "summary": {
        "relevancy_score": 0.0
    },
    "details": {
        "atomic_facts": [
            "The assistant greets with 'Hello!'.",
            "The assistant offers help today.",
            "The assistant invites questions or requests for assistance.",
            "The assistant is available to provide information.",
            "The assistant is available to provide support.",
            "The assistant asks if there is something specific to know or discuss."
        ],
        "relevancy_list": [
            0,
            0,
            0,
            0,
            0,
            0
        ],
        "relevancy_response": "{\n    \"chain_of_thought\": [\n        \"NOT RELEVANT: The fact is about greeting, not relevant to the question 'Hi'.\",\n        \"NOT RELEVANT: The fact is about offering help, not relevant to the question 'Hi'.\",\n        \"NOT RELEVANT: The fact is about inviting questions, not relevant to the question 'Hi'.\",\n        \"NOT RELEVANT: The fact is about providing information, not relevant to the question 'Hi'.\",\n        \"NOT RELEVANT: The fact is about providing support, not relevant to the question 'Hi'.\",\n        \"NOT RELEVANT: The fact is about asking for specific topics, not relevant to the question 'Hi'.\"\n    ],\n    \"relevancy\": [\n        0,\n        0,\n        0,\n        0,\n        0,\n        0\n    ]\n}",
        "relevancy_latency": 2.335660696029663
    }
}