Overview
The Extraction Sessions API maintains conversation history for Gemini AI during claim extraction. It enables multi-turn context by storing the complete message history between the user (system prompts + transcripts) and the AI model (claim extraction responses). This allows the claim extraction process to maintain context across multiple extraction runs, improving accuracy and consistency. Function Types:- Internal Query:
getByDebate - Internal Mutation:
upsert
getByDebate
Parameters
The ID of the debate to retrieve the session for
Returns
The session object containing message history, or null if no session exists yet
Session Object Structure
Unique session identifier
Convex automatic creation timestamp
ID of the associated debate
Array of conversation messages in chronological order
Message Object Structure
The role of the message sender:
"user": System prompts and transcript inputs"model": Gemini AI responses with extracted claims
The message content (prompt text or AI response)
Behavior
- Uses
by_debateindex for efficient lookup - Returns first (and only) session for the debate
- Returns
nullif no session has been created yet
upsert
Parameters
The ID of the debate
The complete array of messages representing the conversation history
The role of each message
The content of each message
Returns
Returns null on success
Behavior
- Queries for existing session using
by_debateindex - If session exists:
- Updates the existing session’s
messagesarray viapatch
- Updates the existing session’s
- If session doesn’t exist:
- Creates new session with provided messages via
insert
- Creates new session with provided messages via
- Replaces entire message array (not append)
The
upsert function replaces the entire message array. To append messages, you must:- Fetch existing session with
getByDebate - Concatenate new messages to existing array
- Call
upsertwith complete array
Message Validation Schema
Usage Pattern
The typical flow for maintaining extraction context:Example Flow
First Extraction:Benefits of Session History
- Contextual Awareness: Gemini can reference previously extracted claims
- Consistency: Maintains consistent claim formatting and extraction patterns
- Deduplication: AI can avoid extracting duplicate claims
- Progressive Refinement: Model learns debate-specific patterns
- Multi-turn Reasoning: Enables complex extraction across multiple passes
Database Relationship
- One-to-one relationship: Each debate has at most one extraction session
- Session persists across multiple extraction runs
- Session is never deleted (maintains full history)
- Indexed by
debateIdfor efficient lookups