Skip to main content
POST
/
contexts
/
{context_name}
/
data
curl -X POST \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "body": {
      "interaction_type": "support_request",
      "user_message": "I cant log into my account even after resetting password",
      "timestamp": "2024-01-15T14:30:00Z",
      "previous_attempts": 3,
      "user_emotion": "frustrated"
    },
    "scopes": {
      "user_id": 123,
      "project": "web-app"
    }
  }' \
  https://api.contextbase.dev/v1/contexts/user-interactions/data
{
  "message": "Data published successfully"
}

Overview

The publish endpoint allows you to add unstructured data or files to a context. This is how you build up the “memory” in Contextbase’s compression engine - by continuously publishing user interactions, system events, profile updates, documents, and other relevant data that will later be compressed into context-rich prompts for your LLMs.

Path Parameters

context_name
string
required
Name of the context to publish to (e.g., “user-interactions”, “knowledge-base”)

Request Body

You can provide either a body object or a file object, but not both.
body
object
Unstructured data to publish to the context. This can be any JSON object containing information you want to enrich your context with - user messages, profile updates, system events, etc.
file
object
File to upload and publish to the context. The file will be processed and its content will be made available for context resolution.Supported file types: PDF, CSV, DOC, DOCX, XLS, XLSX, HTML, TXT, MD, PNG, JPEG, WEBP
scopes
object
Scoping parameters for the published data. These determine which resolved contexts will include this data - essential for personalization and data organization.

Response

message
string
required
Confirmation message indicating successful publication to the context.

Example Request

curl -X POST \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "body": {
      "interaction_type": "support_request",
      "user_message": "I cant log into my account even after resetting password",
      "timestamp": "2024-01-15T14:30:00Z",
      "previous_attempts": 3,
      "user_emotion": "frustrated"
    },
    "scopes": {
      "user_id": 123,
      "project": "web-app"
    }
  }' \
  https://api.contextbase.dev/v1/contexts/user-interactions/data

File Upload Example

curl -X POST \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "file": {
      "name": "api-documentation.pdf",
      "mime_type": "application/pdf",
      "base64": "JVBERi0xLjQKJcOkw7zDtsO..."
    },
    "scopes": {
      "project": "web-app",
      "version": "v2"
    }
  }' \
  https://api.contextbase.dev/v1/contexts/documents/data

Example Response

{
  "message": "Data published successfully"
}

Error Responses

{
  "message": "Static contexts cannot be published to"
}

Use Cases

  • User Interaction Memory: Publish chat messages, user questions, feedback, and preferences to build user-specific context
  • Behavioral Data: Track user actions, feature usage, and interaction patterns for personalized AI responses
  • System Events: Log important system changes, errors, or updates that might be relevant for support contexts
  • Profile Updates: Maintain current user information, role changes, or permission updates
  • Conversation History: Build memory for chatbots by publishing both user messages and AI responses
  • Document Uploads: Upload PDFs, spreadsheets, images, and other files to enrich context with document content
  • Knowledge Base Management: Publish documentation, guides, and reference materials for AI to reference
  • Image Analysis: Upload images for visual context and analysis capabilities

Context Types

Static Contexts

Static contexts contain fixed content that doesn’t change:
  • System prompts and instructions
  • General knowledge base articles
  • Product documentation
  • Universal policies and guidelines

Dynamic Contexts

Dynamic contexts accept new publications and can be scoped:
  • User-specific interaction history (scoped by user_id)
  • Project-specific information (scoped by project)
  • Environment-specific configurations (scoped by environment)
  • Session-specific data (scoped by session_id)

Notes

  • Only dynamic contexts accept new publications. Static contexts will return a 422 error.
  • Some contexts may require specific scopes to be present. Check the context configuration for requirements.
  • Published data becomes immediately available when resolving the context.
  • Data is compressed and filtered during context resolution, so you can publish freely without worrying about overwhelming your prompts.
  • When uploading files, ensure they are in one of the supported formats: PDF, CSV, DOC, DOCX, XLS, XLSX, HTML, TXT, MD, PNG, JPEG, WEBP.
  • Files are processed and their content is extracted for context resolution. Large files may take longer to process.