Skip to main content
Get up and running with Meibel AI by building a simple document analysis application with confidence scoring.

Prerequisites

Before starting, ensure you have:

Your First Application

Let’s build a simple application that analyzes text with confidence scoring and decision tracing.

1. Initialize the Client

from meibelai import Meibelai
import os

# Initialize the client with your API key
client = Meibelai(
    api_key_header=os.getenv("MEIBELAI_API_KEY_HEADER")
)

# Verify connection
print("Connected to Meibel AI!")

2. Create a Datasource

Store your documents in a datasource for analysis:
# Create a datasource for your documents
datasource = client.datasources.create(
    name="Quick Start Documents",
    description="Sample documents for testing"
)

print(f"Created datasource: {datasource.id}")

3. Add Content

Add some sample content to analyze:
# Add a document
document = client.dataelements.create(
    datasource_id=datasource.id,
    name="Company Policy",
    content="""
    Our company values innovation and customer satisfaction. 
    We offer flexible work arrangements including remote work 
    up to 3 days per week. All employees receive comprehensive 
    health benefits and professional development support.
    """,
    metadata={
        "type": "policy",
        "category": "hr"
    }
)

print(f"Added document: {document.id}")

4. Analyze with Confidence Scoring

Use RAG to analyze the content with confidence scoring:
# Ask a question about the content
response = client.rag.chat(
    messages=[
        {
            "role": "user", 
            "content": "What is the remote work policy?"
        }
    ],
    datasource_ids=[datasource.id],
    confidence_threshold=0.7,
    execution_control={
        "enable_tracing": True,
        "temperature": 0.3
    }
)

# Display results
print(f"\nAnswer: {response.choices[0].message.content}")
print(f"Confidence Score: {response.confidence_score}")

# Check if confidence meets threshold
if response.confidence_score >= 0.7:
    print("✓ High confidence response")
else:
    print("⚠ Low confidence - may need review")

5. View Decision Trace

Understand how the AI arrived at its answer:
# Access trace information if available
if hasattr(response, 'trace'):
    print("\nDecision Trace:")
    for step in response.trace.steps:
        print(f"- {step.action}: {step.details}")

Complete Example

Here’s the full code in one script:
from meibelai import Meibelai
import os

def main():
    # Initialize client
    client = Meibelai(
        api_key_header=os.getenv("MEIBELAI_API_KEY_HEADER")
    )
    
    # Create datasource
    datasource = client.datasources.create(
        name="Quick Start Demo",
        description="Demo for quick start guide"
    )
    
    # Add content
    client.dataelements.create(
        datasource_id=datasource.id,
        name="Sample Policy",
        content="Employees can work remotely up to 3 days per week.",
        metadata={"type": "policy"}
    )
    
    # Analyze with confidence scoring
    response = client.rag.chat(
        messages=[{"role": "user", "content": "What is the remote work policy?"}],
        datasource_ids=[datasource.id],
        confidence_threshold=0.7
    )
    
    # Display results
    print(f"Answer: {response.choices[0].message.content}")
    print(f"Confidence: {response.confidence_score}")
    
    # Cleanup (optional)
    client.datasources.delete(datasource.id)
    print("\nDemo complete!")

if __name__ == "__main__":
    main()

Run Your Application

python quickstart.py
Expected output:
Answer: Employees can work remotely up to 3 days per week.
Confidence: 0.92
Demo complete!

What’s Next?

Now that you’ve built your first Meibel application, explore more advanced features:

Confidence Scoring

Learn how confidence scoring works and how to tune thresholds

Decision Tracing

Understand the complete decision-making process

Examples

See real-world implementation patterns

API Reference

Explore all available endpoints and options

Troubleshooting

Make sure you’ve installed the SDK:
pip install git+https://github.com/meibel-ai/meibelai-python.git
Verify your API key is set:
echo $MEIBELAI_API_KEY_HEADER
Try adding more context to your datasource or adjusting the temperature parameter.