Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.meibel.ai/llms.txt

Use this file to discover all available pages before exploring further.

This guide walks you through the three pillars of Meibel — Context, Agents, and Confidence — in a single end-to-end workflow. By the end, you will have parsed a document, built a knowledge base, created an agent, and chatted with it.
Before you begin, make sure you have installed an SDK and set your API key.

Step 1: Parse a Document

Start with the Context pillar. Meibel can parse any document (PDF, DOCX, images) and return structured content in a single synchronous call.
import os
from meibel import MeibelClient

client = MeibelClient(api_key=os.environ["MEIBEL_API_KEY"])

with open("document.pdf", "rb") as f:
    result = client.documents.process_document(file=f, file_name="document.pdf")

print(result.content)
process_document handles parsing, OCR, and structuring in one step. The response contains the extracted text, tables, and metadata.

Step 2: Create a Datasource and Upload Content

Documents become searchable once they live inside a datasource — a managed knowledge base that agents can query.
from meibel.models import CreateDatasourceRequest, ConnectorConfig

# Create a datasource
datasource = client.datasources.create_datasource(
    body=CreateDatasourceRequest(
        name="Product Knowledge Base",
        description="Internal product documentation and reports",
        connector=ConnectorConfig(type="managed"),
    )
)
ds_id = datasource.id
print(f"Created datasource: {ds_id}")

# Upload a file into it
with open("report.pdf", "rb") as f:
    client.content.upload_content(file=f, file_name="report.pdf")

# Trigger ingestion so the content becomes searchable
client.content.trigger_ingest(datasource_id=ds_id)
print("Ingestion started")
Ingestion runs asynchronously. Once complete, the content is indexed and available for agent queries.

Step 3: Create an Agent

Now move to the Agentic pillar. An agent combines a system prompt with one or more datasources to answer questions grounded in your content.
from meibel.models import CreateAgentDefinitionRequest, PublishAgentDefinitionRequest

# Create the agent
agent = client.agents.create_agent(
    body=CreateAgentDefinitionRequest(
        display_name="Product Assistant",
        description="Answers questions about product documentation",
        instructions="You are a helpful product assistant. Answer questions using only the provided knowledge base. If you don't know the answer, say so.",
    )
)
agent_id = agent.id
print(f"Created agent: {agent_id}")

# Publish it so it can accept chat sessions
client.agents.publish_agent(
    agent_id=agent_id,
    body=PublishAgentDefinitionRequest(commit_message="Initial release"),
)
print("Agent published")

Step 4: Chat with the Agent

Start a session and send a message. Each session maintains its own conversation history.
from meibel.models import ChatMessageRequest

# Create a session
session = client.agents.create_session(agent_id=agent_id)
session_id = session.session_id
print(f"Session: {session_id}")

# Send a message
response = client.sessions.send_chat_message(
    session_id=session_id,
    body=ChatMessageRequest(user_message="What does the product do?"),
)
print(response.message)

Step 5: Stream a Response

For a real-time experience, stream the agent’s reply token-by-token. This is ideal for chat interfaces where you want to show output as it is generated.
stream = client.sessions.send_chat_message_stream(
    session_id=session_id,
    body=ChatMessageRequest(user_message="Summarize the key features"),
)
for event in stream:
    print(event.delta, end="", flush=True)
print()  # newline after stream completes

Step 6: Check Confidence

The Confidence pillar is built into every response. When an agent answers a question, the response includes confidence metadata that tells you how well-grounded the answer is in your datasource content.
response = client.sessions.send_chat_message(
    session_id=session_id,
    body=ChatMessageRequest(user_message="What is the pricing model?"),
)

print(f"Answer: {response.message}")
print(f"Confidence: {response.confidence.score}")
print(f"Sources: {len(response.confidence.citations)} citation(s)")

for citation in response.confidence.citations:
    print(f"  - {citation.source}: {citation.text[:80]}...")
Confidence scores let you build guardrails — for example, flagging low-confidence answers for human review or requiring a minimum score before showing a response to end users.

What’s Next?

You have now used all three pillars of the Meibel platform. Dive deeper into each area:

Context Engineering

Learn how datasources, documents, and ingestion work together

Agents

Understand agent definitions, publishing, and versioning

Confidence Scoring

Deep dive into confidence metrics, citations, and thresholds

Streaming Guide

SSE streaming patterns and best practices