Skip to content

Commit c34ad20

Browse files
committed
Add more information about the tools to use
1 parent ebe63a9 commit c34ad20

File tree

1 file changed

+213
-6
lines changed

1 file changed

+213
-6
lines changed

reference/api/chats.mdx

Lines changed: 213 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,218 @@ The chat feature integrates with Meilisearch's authentication system:
402402
403403
## Tool calling
404404
405-
The chat feature uses internal tool calling to search your indexes.
406-
But there are a bunch of tools that are automatically invoked based on the user's questions:
405+
The chat feature uses internal tool calling to search your indexes and provide enhanced user experience. For optimal performance and user experience, you should declare three special tools in your chat completion requests. These tools are handled internally by Meilisearch and provide real-time feedback about search operations, conversation context, and source documents.
407406
408-
- `_meiliSearchProgress`: Reports search progress
409-
- `_meiliAppendConversationMessage`: Maintains conversation context
410-
- `_meiliSearchSources`: Displays source documents used in responses
407+
### Overview of Special Tools
411408
412-
You must declare those tools when using the chat completion API to have the best experience.
409+
- **`_meiliSearchProgress`**: Reports real-time search progress and operations
410+
- **`_meiliAppendConversationMessage`**: Maintains conversation context for better responses
411+
- **`_meiliSearchSources`**: Provides source documents used in generating responses
412+
413+
### Tool Declaration
414+
415+
Include these tools in your request's `tools` array to enable enhanced functionality:
416+
417+
<CodeGroup>
418+
419+
```json Complete Tool Declaration
420+
{
421+
"model": "gpt-3.5-turbo",
422+
"stream": true,
423+
"messages": [
424+
{
425+
"role": "user",
426+
"content": "What is Meilisearch?"
427+
}
428+
],
429+
"tools": [
430+
{
431+
"type": "function",
432+
"function": {
433+
"name": "_meiliSearchProgress",
434+
"description": "Provides information about the current Meilisearch search operation",
435+
"parameters": {
436+
"type": "object",
437+
"properties": {
438+
"call_id": {
439+
"type": "string",
440+
"description": "The call ID to track the sources of the search"
441+
},
442+
"function_name": {
443+
"type": "string",
444+
"description": "The name of the function we are executing"
445+
},
446+
"function_parameters": {
447+
"type": "string",
448+
"description": "The parameters of the function we are executing, encoded in JSON"
449+
}
450+
},
451+
"required": ["call_id", "function_name", "function_parameters"],
452+
"additionalProperties": false
453+
},
454+
"strict": true
455+
}
456+
},
457+
{
458+
"type": "function",
459+
"function": {
460+
"name": "_meiliAppendConversationMessage",
461+
"description": "Append a new message to the conversation based on what happened internally",
462+
"parameters": {
463+
"type": "object",
464+
"properties": {
465+
"role": {
466+
"type": "string",
467+
"description": "The role of the messages author, either `role` or `assistant`"
468+
},
469+
"content": {
470+
"type": "string",
471+
"description": "The contents of the `assistant` or `tool` message. Required unless `tool_calls` is specified."
472+
},
473+
"tool_calls": {
474+
"type": ["array", "null"],
475+
"description": "The tool calls generated by the model, such as function calls",
476+
"items": {
477+
"type": "object",
478+
"properties": {
479+
"function": {
480+
"type": "object",
481+
"description": "The function that the model called",
482+
"properties": {
483+
"name": {
484+
"type": "string",
485+
"description": "The name of the function to call"
486+
},
487+
"arguments": {
488+
"type": "string",
489+
"description": "The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function."
490+
}
491+
}
492+
},
493+
"id": {
494+
"type": "string",
495+
"description": "The ID of the tool call"
496+
},
497+
"type": {
498+
"type": "string",
499+
"description": "The type of the tool. Currently, only function is supported"
500+
}
501+
}
502+
}
503+
},
504+
"tool_call_id": {
505+
"type": ["string", "null"],
506+
"description": "Tool call that this message is responding to"
507+
}
508+
},
509+
"required": ["role", "content", "tool_calls", "tool_call_id"],
510+
"additionalProperties": false
511+
},
512+
"strict": true
513+
}
514+
},
515+
{
516+
"type": "function",
517+
"function": {
518+
"name": "_meiliSearchSources",
519+
"description": "Provides sources of the search",
520+
"parameters": {
521+
"type": "object",
522+
"properties": {
523+
"call_id": {
524+
"type": "string",
525+
"description": "The call ID to track the original search associated to those sources"
526+
},
527+
"documents": {
528+
"type": "object",
529+
"description": "The documents associated with the search (call_id). Only the displayed attributes of the documents are returned"
530+
}
531+
},
532+
"required": ["call_id", "documents"],
533+
"additionalProperties": false
534+
},
535+
"strict": true
536+
}
537+
}
538+
]
539+
}
540+
```
541+
542+
</CodeGroup>
543+
544+
### Tool Functions Explained
545+
546+
#### `_meiliSearchProgress`
547+
548+
This tool reports real-time progress of internal search operations. When declared, Meilisearch will call this function whenever search operations are performed in the background.
549+
550+
**Purpose**: Provides transparency about search operations and reduces perceived latency by showing users what's happening behind the scenes.
551+
552+
**Arguments**:
553+
- `call_id`: Unique identifier to track the search operation
554+
- `function_name`: Name of the internal function being executed (e.g., "_meiliSearchInIndex")
555+
- `function_parameters`: JSON-encoded string containing search parameters like `q` (query) and `index_uid`
556+
557+
**Example Response**:
558+
```json
559+
{
560+
"function": {
561+
"name": "_meiliSearchProgress",
562+
"arguments": "{\"call_id\":\"89939d1f-6857-477c-8ae2-838c7a504e6a\",\"function_name\":\"_meiliSearchInIndex\",\"function_parameters\":\"{\\\"index_uid\\\":\\\"movies\\\",\\\"q\\\":\\\"search engine\\\"}\"}"
563+
}
564+
}
565+
```
566+
567+
#### `_meiliAppendConversationMessage`
568+
569+
Since the `/chats/{workspace}/chat/completions` endpoint is stateless, this tool helps maintain conversation context by requesting the client to append internal messages to the conversation history.
570+
571+
**Purpose**: Maintains conversation context for better response quality in subsequent requests by preserving tool calls and results.
572+
573+
**Arguments**:
574+
- `role`: Message author role ("user" or "assistant")
575+
- `content`: Message content (for tool results)
576+
- `tool_calls`: Array of tool calls made by the assistant
577+
- `tool_call_id`: ID of the tool call this message responds to
578+
579+
**Example Response**:
580+
```json
581+
{
582+
"function": {
583+
"name": "_meiliAppendConversationMessage",
584+
"arguments": "{\"role\":\"assistant\",\"tool_calls\":[{\"id\":\"call_ijAdM42bixq9lAF4SiPwkq2b\",\"type\":\"function\",\"function\":{\"name\":\"_meiliSearchInIndex\",\"arguments\":\"{\\\"index_uid\\\":\\\"movies\\\",\\\"q\\\":\\\"search engine\\\"}\"}}]}"
585+
}
586+
}
587+
```
588+
589+
#### `_meiliSearchSources`
590+
591+
This tool provides the source documents that were used by the LLM to generate responses, enabling transparency and allowing users to verify information sources.
592+
593+
**Purpose**: Shows users which documents were used to generate responses, improving trust and enabling source verification.
594+
595+
**Arguments**:
596+
- `call_id`: Matches the `call_id` from `_meiliSearchProgress` to associate queries with results
597+
- `documents`: JSON object containing the source documents with only displayed attributes
598+
599+
**Example Response**:
600+
```json
601+
{
602+
"function": {
603+
"name": "_meiliSearchSources",
604+
"arguments": "{\"call_id\":\"abc123\",\"documents\":[{\"id\":197302,\"title\":\"The Sacred Science\",\"overview\":\"Diabetes. Prostate cancer...\",\"genres\":[\"Documentary\",\"Adventure\",\"Drama\"]}]}"
605+
}
606+
}
607+
```
608+
609+
### Implementation Best Practices
610+
611+
1. **Always declare all three tools** for the best user experience
612+
2. **Handle progress updates** by displaying search status to users during streaming
613+
3. **Append conversation messages** as requested to maintain context for future requests
614+
4. **Display source documents** to users for transparency and verification
615+
5. **Use the `call_id`** to associate progress updates with their corresponding source results
616+
617+
<Note>
618+
These special tools are handled internally by Meilisearch and are not forwarded to the LLM provider. They serve as a communication mechanism between Meilisearch and your application to provide enhanced user experience features.
619+
</Note>

0 commit comments

Comments
 (0)