Implementing streaming, batch search, and conversation-aware matching
Take your integration to the next level with advanced features designed for complex agentic workflows.
For agents that need to deliver results in real-time, VKRA supports Server-Sent Events (SSE). This allows you to render products as soon as they are found, rather than waiting for the entire search to complete.
To enable streaming, set stream: true in your search request.
const response = await fetch('https://api.vkra.org/search', {
method: 'POST',
headers: {
'x-api-key': 'YOUR_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: "high-end gaming laptops",
stream: true
})
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
const events = chunk.split('\n\n');
events.forEach(event => {
if (event.startsWith('event: product')) {
const data = JSON.parse(event.replace('event: product\ndata: ', ''));
renderProduct(data); // Render product immediately
}
});
}To provide more relevant recommendations across multiple turns of a conversation, you can use session_id and conversation_context.
{
"query": "What about something from Sony?",
"session_id": "550e8400-e29b-41d4-a716-446655440000",
"conversation_context": [
{"role": "user", "content": "I'm looking for noise-cancelling headphones"},
{"role": "assistant", "content": "Sure! I can help with that. Are you looking for over-ear or in-ear?"},
{"role": "user", "content": "Over-ear please"}
]
}If your agent identifies multiple user intents simultaneously (e.g., "I need a new laptop and a carrying case"), you can process them in a single batch request to reduce round-trips.
curl -X POST https://api.vkra.org/search/batch \
-H "x-api-key: YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"queries": [
{ "query": "high-end gaming laptop", "limit": 1 },
{ "query": "laptop carrying case", "limit": 1 }
]
}'You can request a tool definition that can be directly ingested by models like OpenAI or Anthropic. This helps the model understand how to use the search tool effectively.
{
"query": "find a gift for a coffee lover",
"tool_definition": {
"format": "openai_function",
"include_examples": true
}
}The response will include a tool_definition in the metadata that you can pass directly to your model's function calling interface.