Using records in flows
Integrate records into flows to provide context, personalize responses, and implement RAG (Retrieval Augmented Generation) patterns.
Common patterns
RAG: Question answering with context
Retrieve relevant documents and include them in AI prompts:
- Vector Search: Find docs matching user question (semantic search)
- Run Code: Extract and format retrieved content
- Run Task: Generate answer using retrieved context
Example prompt:
Personalization with customer data
Retrieve customer profile and use it for personalized responses:
- Get Record: Get customer by ID, name, or type
- Run Task: Generate response referencing customer data
Example:
Caching API results
Save expensive API calls in records:
- Get Record: Check if a cached result exists
- Conditional Logic: If cache miss, call external API
- Upsert Record: Save API response for future use
The output of the final step is the cached or fresh result.
Conversation history
Store chat logs for context in future interactions:
- Get Record: Get conversation history by user ID
- Run Task: Generate response with conversation context
- Upsert Record: Update conversation history with new exchange
Record lookups
Fetch a single record by ID or by type and name with Get Record:
Use in conditionals to check if a record exists:
Or fetch every match with List Records:
List Records always returns an array, so check its length instead of comparing to null:
Multi-record retrieval
Use a List Records step or a Vector Search step to get multiple results:
- Vector Search: Find matching products by semantic similarity
- Run Code: Extract and format results
- Run Task: Process or summarize the matches
Updating records from flows
Flows can create or update records using the Upsert Record step. The step identifies records by type and name, and stores the contents of a source variable as metadata:
There is also an Update Record step for modifying specific metadata fields on an existing record without replacing the entire metadata object.
Use Vector Search for unstructured queries (“How do I…?”), Get Record for a single structured lookup (“Get customer with ID 12345”), and List Records for structured lookups that may return several matches (“Get all open tickets for this customer”).
Optimizing record usage
- Limit search results: Only retrieve what you need
- Cache retrieved data: Store in variables, don’t retrieve multiple times
- Use specific types: Searching within a type is faster than all records
- Filter before semantic search: Narrow scope for better performance
Error handling
Handle a missing record from Get Record gracefully:
List Records returns an empty array rather than null when nothing matches, so check .length instead:
Best practices
- Keep record metadata concise: Only store fields you’ll query or use in prompts
- Use meaningful record types: Organize records logically
- Test search relevance: Verify semantic search returns appropriate results
- Monitor record count: Large record sets need indexed fields
- Version control: Don’t delete old records; mark them inactive instead
Example: Full RAG flow
The answer lives in the final step’s output variable (answerQuestion above), which is returned as the flow result.
Next steps
- Using record steps (get/list/upsert) for detailed step configuration
- Filtering and searching records for advanced queries
- Creating and managing records to populate your record store
- Using prompt steps to generate responses with record context