Working with Domain Types¶
QType provides several built-in domain types that represent common AI and chat application data structures.
Overview of Domain Types¶
QType includes these key domain types:
ChatMessage
- Structured chat messages with roles and content blocksChatContent
- Individual content blocks (text, images, etc.) within messagesEmbedding
- Vector embeddings with metadataMessageRole
- Enumeration of message sender roles
These types help you build robust AI applications with proper data structure and validation.
ChatMessage: The Foundation of Conversational AI¶
ChatMessage¶
A standard, built-in representation of a chat message.
- role (
MessageRole
): The role of the message sender (e.g., 'user', 'assistant'). - blocks (
list[ChatContent]
): The content blocks of the chat message, which can include text, images, or other media.
Understanding ChatMessage Structure¶
ChatMessage
is a composite type that represents a single message in a conversation:
# Basic chat message structure
variables:
- id: user_input
type: ChatMessage
# Will contain: role + list of content blocks
- id: ai_response
type: ChatMessage
# AI's response with assistant role
Message Roles¶
MessageRole¶
An enumeration.
- assistant: An enumeration.
- chatbot: An enumeration.
- developer: An enumeration.
- function: An enumeration.
- model: An enumeration.
- name: The name of the Enum member.
- system: An enumeration.
- tool: An enumeration.
- user: An enumeration.
- value: The value of the Enum member.
The MessageRole
enum defines who sent the message:
user
- End user inputassistant
- AI model responsesystem
- System instructions/contexttool
- Tool execution resultsfunction
- Function call results (legacy)developer
- Developer notes/debuggingmodel
- Direct model outputchatbot
- Chatbot-specific role
Content Blocks¶
ChatContent¶
No documentation available.
- type (
PrimitiveTypeEnum
): The type of content, such as 'text', 'image', etc. - content (
Any
): The actual content, which can be a string, image data, etc. - mime_type (
str | None
): The MIME type of the content, if known.
Each ChatMessage
contains one or more ChatContent
blocks:
Practical Examples¶
Basic Chat Flow¶
The following creates a simple chat experience that is multi-modal: since ChatMessage
contains mupltiple blocks, the blocks can be of different multimedia types.
id: simple_chat
flows:
- id: chat_conversation
mode: Chat
steps:
- id: llm_step
model:
id: gpt-4o
provider: openai
auth:
id: openai_auth
type: api_key
api_key: ${OPENAI_KEY}
system_message: |
You are a helpful AI assistant.
inputs:
- id: user_message
type: ChatMessage # User's input message
outputs:
- id: assistant_response
type: ChatMessage # AI's response message
Working with Embeddings¶
Embedding¶
A standard, built-in representation of a vector embedding.
- vector (
list[float]
): The vector representation of the embedding. - source_text (
str | None
): The original text that was embedded. - metadata (
dict[str, str] | None
): Optional metadata associated with the embedding.
Basic Embedding Usage¶
id: embedding_example
models:
- id: text_embedder
provider: openai
model_id: text-embedding-3-large
dimensions: 3072
auth: openai_auth
flows:
- id: create_embeddings
steps:
- id: embed_step
model: text_embedder
inputs:
- id: source_text
type: text
outputs:
- id: text_embedding
type: Embedding # Vector + metadata
RAG with Embeddings¶
id: rag_system
models:
- id: embedder
provider: openai
model_id: text-embedding-3-large
dimensions: 3072
auth: openai_auth
indexes:
- id: knowledge_base
name: documents
embedding_model: embedder
flows:
- id: rag_query
steps:
- id: search_step
index: knowledge_base
inputs:
- id: query
type: text
outputs:
- id: search_results
type: array
items:
type: Embedding # Found embeddings with metadata
- id: generate_step
model: gpt-4
system_message: |
Use these search results to answer the question:
{{search_results}}
inputs:
- id: user_question
type: ChatMessage
outputs:
- id: rag_response
type: ChatMessage