Skip to main content
This guide takes you from an empty project to a working example that introduces the core functionality of the Meibel platform. You will parse a document, build a searchable knowledge base, create an agent and chat with it, extract structured data from a document, then run that same extraction across an entire datasource as a batch. By the end you will have a small but complete pipeline: raw PDFs going in, searchable knowledge and structured data coming out. The example uses material safety data sheets (MSDS), the documents that ship with chemical products to describe their hazards and safe handling. They work well for this because they are real documents built around a standard set of fields, yet they still vary from one manufacturer to the next. That mix of structure and variation is what you meet in most real-world data, and it gives each step something meaningful to work on.
Before you begin, install an SDK and set your API key. Each example below assumes MEIBEL_API_KEY is set in your environment.

1. Parse a document

Start by parsing a single document. It is the fastest way to see the platform do real work, and it confirms your SDK and API key are set up correctly before you build anything larger. Parsing turns a PDF, including scanned or image-based pages, into clean structured content you can read or hand to another step. The call runs synchronously, so the result comes straight back.
This single call handles parsing, OCR, and structuring, then returns the extracted content in result. Running it synchronously like this suits smaller files or testing a lighter workflow. For larger documents or higher volumes, submit the job asynchronously and poll for the result instead. See the document processing guide for that workflow.

2. Create a datasource and upload content

Parsing one document is useful on its own, but most work spans many documents that you want to search across and keep up to date. A datasource is a managed knowledge base for exactly that: you add files to it, and the platform parses, analyzes, indexes, and keeps them searchable. The agent you build in the next step will draw on this datasource to ground its answers. In this step you create a datasource, upload a few MSDS PDFs, and trigger ingestion. Download the sample sheets first, then upload them from your working directory:
Ingestion runs asynchronously. Once your files are uploaded, each one is parsed, its content is extracted, and the results are indexed into searchable data elements. The loop above polls until ingestion reaches a terminal state, because the agent you build next can only draw on content that is fully ingested. The datasources guide covers tracking ingestion status in more detail.

3. Create an agent and chat with it

An agent is where your context turns into something you can use. It brings together what it knows, how it reasons, and what it produces: the datasources it can draw on, a system prompt that shapes its responses, and an optional schema for structured output. It can also call tools to improve an answer or take action, such as running a targeted search or querying a database. A sensitive tool can require human approval before it runs. Bound to your MSDS datasource, an agent retrieves the relevant content on its own to ground each answer, point to the source it drew from, and decline to guess when the answer is not there. Create an agent over the datasource from the previous step, then publish it. Publishing freezes the configuration as a versioned, reproducible release that can hold chat sessions.
Now open a session and ask a question. A session keeps its own conversation history, so the agent can follow up on earlier messages. Each response carries both the answer and the sources the agent drew on, so you can check where it came from.

Stream a response

Streaming sends the response back in pieces as it is generated, instead of making you wait for the whole thing. It helps anywhere a wait would otherwise feel slow: a chat interface that shows the answer as it forms, a long-running task you want to report progress on, or a downstream process that can start on early output before the rest arrives. Send the message to the streaming endpoint and read events as they come in.
The stream delivers Server-Sent Events. Each event carries a type and a JSON payload. Types include connected, status, tool_call / tool_result (emitted when the agent retrieves from a datasource), partial_response (empty while a tool runs), and completion. The complete answer is always in the completion event’s data.message. Read that for the final text. Each partial_response carries the full text generated up to that point, so print the newly-added suffix for a live typing effect. See the streaming guide for the full event reference and semantics. To attach a file to a streaming turn, pass a file and file name as the second and third arguments (both optional).

4. Extract structured data from a document

Chat gives you answers in prose. Often you want structured data instead: the same fields, in the same shape, ready to store or compare. For that you define an artifact schema, a JSON Schema that names the fields you want, and have the platform extract a document into that shape. Start with the schema. It lists the chemical-property and safety fields to pull from each sheet. Every field is optional, so the platform returns null for anything a given sheet does not contain.
Now extract a single sheet against that schema. This runs synchronously and returns the structured data directly, so you can confirm the fields come back the way you expect before running it at scale.
The result comes back as structured data keyed by the fields you defined, ready to store, compare, or hand to another system. The same schema drives the batch run in the next step.

5. Run extraction across a datasource in batch

Extracting a document at a time works well for interactive, on-demand extraction, and for checking that your schema behaves. When you need the same structured extraction from every document in a datasource, run it as a batch: point an agent at the datasource, and it processes each file and returns one structured result per input document. The agent’s instructions are what drive the extraction, so give it a focused extraction prompt. This one works well for safety data sheets:
A few things make this a strong extraction prompt:
  • A clear role and task. “You are an MSDS data extractor” and “extract the following … from the attached document” keep the agent focused on extraction rather than conversation.
  • An explicit output contract. It asks for a structured JSON artifact by name, matching the schema you registered.
  • Every field named and described. A short description per field tells the agent exactly what to pull and resolves ambiguity between similar fields.
  • A rule for missing data. “Use null for any field not found” keeps the agent faithful to the document instead of guessing.
  • Grounded to the source. “From the attached document” anchors the extraction to the file rather than the model’s prior knowledge.
The chat agent from step 3 is tuned for conversation. Rather than repurpose it, create a dedicated extraction agent: give it the extraction prompt as its instructions and attach the schema it should produce, referenced by name as in step 4. Keeping the two separate leaves your chat assistant untouched and makes each agent’s job explicit.
Now define a batch over the datasource, execute it, and poll for results.
When the batch run completes, the execution reports how many items succeeded and failed, and each item carries the structured data the agent produced for its document. For a long-running batch, you can stream live progress instead of polling. See the error handling guide for retrying failed items. A batch definition is reusable. Execute it again whenever the datasource changes, and each run works against its latest ingested state. By default, each run writes its results to a new output datasource that the platform creates for you, so the results live on as data you can query later. To collect results in a specific place, pin an output datasource when you define the batch.

What’s next

You now have a complete Meibel pipeline: documents parsed, a searchable knowledge base, an agent you can chat with, and structured data pulled from a single document and from a whole datasource at once. Each step here is the simplest version of something you can take much further. Explore the ideas behind them next:

Agents

Agent definitions, tools, publishing, and versioning

Confidence Scoring

How Meibel evaluates the quality of an agent’s work

Streaming

Streaming patterns for chat and processing