Four signals converge in assemble_rag_chat_context; format_rag_system_prompt builds the system side for your LLM.
Weaving these together β rather than only querying a knowledge base in isolation β is what separates a generic AI response from one that feels genuinely helpful and contextually aware.
autoplay_sdk.rag_query provides the framework to assemble these signals into a single, structured context block ready for any chat LLM.
This is not
RagPipeline (ingestion β vector store). rag_query is specifically for answering a user message using structured, multi-signal context at query time.What it optimizes for
User query
The current message from the user β the question being answered right now.
Real-time events
What the user is doing in your product at this moment, including optional delta activity since their last chat message via
session_activity_since.Conversation history
Prior turns in the conversation, surfaced via
ChatMemoryProvider.conversation_turns.Knowledge base
Retrieved records from your KB via
KnowledgeBaseRetriever on RagChatProviders when configured. The SDK is vendor-agnostic β swap in Zep, Postgres, Atlas, or any other backend behind the provided protocols.Entry point
system_text bundles all three signals β query, events, and history β into a single prompt your LLM can reason over without additional orchestration.
Delta activity: since last chat message
To give your LLM visibility into product actions that happened after the userβs previous message, persist an inbound watermark per thread and pass its value into assembly.1
Load the previous inbound timestamp
Before calling
assemble_rag_chat_context, retrieve the watermark from your store:2
Pass the cutoff into assembly
3
Advance the cursor after replying
Once the assistant reply is successfully sent, move the watermark forward:
ChatWatermarkScope(conversation_id=..., product_id=...) (plus optional tenant_id) to key threads consistently across your store.
For the store itself:
- Production: implement
InboundWatermarkStorebacked by Redis or SQL. - Development / testing: use the built-in
InMemoryInboundWatermarkStore.
Default prompts
The SDK ships versioned prompt dicts (each withname, description, version, and content fields):
Import from
autoplay_sdk.prompts or use the root package re-exports.
Observability
The SDK does not configure logging for you. Enable debug output from the assembly step:
See Logging for full conventions covering the
autoplay_sdk.* namespace, lazy % formatting, and safe extra fields.
See also
RagPipeline
Embedding and upsert from the event stream β the ingestion side of RAG.
ContextStore
enrich(session_id, query) for retrieval queries at the overview level.