You can use Quotient’s SDK to log inputs and outputs from your retrieval or search-augmented AI applications.

Initialize the Logger

Initialize the Quotient logger with configuration settings for your application:

from quotientai import QuotientAI

quotient = QuotientAI(api_key="your-quotient-api-key")

logger = quotient.logger.init(
    app_path="my-first-app",
    environment="dev",
)

Parameters:

app_name
string
required

Name of your application. Core parameter used to identify the source of logs in the Quotient dashboard.

environment
string
required

Environment where your application is running (e.g., “dev”, “staging”, “prod”). Core parameter used to help segregate logs by deployment environment.

tags
object

Key-value pairs for categorizing and filtering logs. Useful for slicing analytics by dimensions like customer, feature, model version, etc.

Example: {"model": "gpt-4", "feature": "customer-support"}

sample_rate
float
default:"1.0"

Value that determines what percent of logs to persist. Valid range of 0.0 to 1.0.

hallucination_detection
boolean
default:"false"

Enable automatic detection of potential hallucinations in model outputs.

hallucination_detection_sample_rate
float
default:"0.0"

Value that determines what percent of logs to run hallucination detection on. Valid range of 0.0 to 1.0.

Returns:

QuotientLogger
object

A QuotientLogger object.

Send Logs

Log model interactions with context and metadata for analysis.

log_id = logger.log(
    user_query="How do I cook a goose?",
    model_output="The capital of France is Paris",
    documents=["Here is an excellent goose recipe..."]
)

Parameters:

user_query
string
required

The input query or prompt sent to the model.

model_output
string
required

The response generated by the model.

documents
array
required

List of document contents used as context for the model. Can be strings or dictionaries with page_content and optional metadata.

Used in hallucination detection and attribution analysis.

If a dictionary is passed, it must have the key page_content, containing the document text, and optionally metadata , containing any document metadata you want to capture about the document.

Example:

[
    "Sample Document 1 without metadata",
    {"page_content": "Sample Document 2 with metadata", "metadata": {"source": "google.com"},
    {"page_content": "Sample Document 3 without metadata"}
]

NOTE: One of documents, message_history, or instructions is required.

message_history
array

Previous messages in the conversation, following the OpenAI message format with role and content keys.

Used in hallucination detection and attribution analysis.

Example:

[
    {"role": "system", "content": "You are an expert on geography."},
    {"role": "user", "content": "What is the capital of France?"},
    {"role": "assistant", "content": "The capital of France is Paris"}
]

NOTE: One of documents, message_history, or instructions is required.

instructions
array

List of instructions provided to the model.

Used in hallucination detection and attribution analysis.

Example:

[
    "You are a helpful assistant that answers questions about the world.",
    "Answer the question in a concise manner. If you are not sure, say 'I don't know'."
]

NOTE: One of documents, message_history, or instructions is required.

tags
object
required

Additional tags to associate with each log entry.

Example: {"model": "gpt-4", "feature": "customer-support"}

Returns:

log_id
string

A UUID representing the unique identifier for the logged event.

Retrieve Logs

Retrieve logs sent to Quotient using the client.

logs = quotient.logs.list()

Returns:

logs
array
required

An array of Log objects containing the following fields:

Asynchronous Python client

You can also use the asynchronous Python client to log data and retrieve logs.

from quotientai import AsyncQuotientAI

quotient = AsyncQuotientAI(api_key="your-quotient-api-key")

logger = quotient.logger.init(
    app_path="my-first-app",
    environment="dev",
    sample_rate=1.0,
    hallucination_detection=True,
    hallucination_detection_sample_rate=1.0,
)

log_id = await logger.log(
    user_query="How do I cook a goose?",
    model_output="The capital of France is Paris",
    documents=["Here is an excellent goose recipe..."]
)

logs = await quotient.logs.list()
print(logs)