Create a namespace and upload documents in a single request. Each document needs a unique id. The namespace is created automatically if it doesn’t exist.
curl -X POST https://api.withcharcoal.com/v1/namespaces/my-docs/documents \ -H "Authorization: Bearer $CHARCOAL_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "documents": [ { "id": "doc-1", "title": "Getting Started with Widgets", "content": "Widgets are the core building block of our platform. To create a widget, navigate to the dashboard and click New Widget.", "category": "tutorial" }, { "id": "doc-2", "title": "Widget API Reference", "content": "The Widget API supports CRUD operations. Use POST /widgets to create a new widget with a name and configuration object.", "category": "reference" }, { "id": "doc-3", "title": "Troubleshooting Widget Errors", "content": "If a widget fails to render, check that the configuration object includes a valid template_id. Common error: WIDGET_TEMPLATE_NOT_FOUND.", "category": "troubleshooting" } ], "schema": { "title": { "type": "string", "is_searchable": true }, "content": { "type": "string", "is_searchable": true }, "category": { "type": "string", "is_filterable": true } } }'
Response
{ "documents_upserted": 3}
You can upload up to 10,000 documents per request. The schema field defines which attributes are searchable (full-text indexed) and filterable. See the Schema guide for the full reference.
Search with natural language. Provide an objective (one sentence describing what you’re looking for) and context (a detailed description of your query):
curl -X POST https://api.withcharcoal.com/v1/namespaces/my-docs/search \ -H "Authorization: Bearer $CHARCOAL_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "objective": "Fix a widget rendering error", "context": "A widget is failing to render and showing WIDGET_TEMPLATE_NOT_FOUND. I need to understand what causes this and how to fix it." }'
Response
{ "session_id": "sess_abc123", "status": "completed", "documents_scanned": 3, "queries_executed": 2, "synthesis": "The WIDGET_TEMPLATE_NOT_FOUND error occurs when the widget configuration object is missing a valid template_id. Check that your configuration includes a template_id that corresponds to an existing template.", "results": [ { "finding": "Widget rendering failures are caused by missing or invalid template_id in the configuration object", "id": "doc-3", "excerpts": [ "If a widget fails to render, check that the configuration object includes a valid template_id. Common error: WIDGET_TEMPLATE_NOT_FOUND." ] } ]}