You also don’t have to rely on the “RAG” semantic search which has to try to match the user input to content just by similarity to what the user wrote, but instead you can offer your categorized knowledge directly to the AI as functions for exploring it, the code you write then fulfilling the listing.
For example, here is a first tier of a function schema that might have a return of a list of articles, a subset of the total. A second similar function could request from a list of actual documents by an index number you provide in the first to return the full texts.
This keeps the context length low and focused. Below was cranked out by an AI by my description of the nesting, and is a structured schema when used with the latest gpt-4o-2024-08-06 and set strict:true.
Here’s how the schema can be structured:
{
"name": "knowledge_retrieval",
"strict": false,
"schema": {
"type": "object",
"properties": {
"knowledge_retrieval": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["products", "help_articles", "recipes"],
"additionalProperties": false
},
"categories": {
"type": "string",
"enum": [
"Electronics", "Books", "Clothing", "Home Appliances",
"Tech Support", "Product Guides", "Account Help", "Payment Issues",
"Vegetarian", "Vegan", "Gluten-Free", "Quick Meals"
],
"additionalProperties": false
}
},
"required": ["type", "categories"],
"additionalProperties": false
}
},
"required": ["knowledge_retrieval"],
"additionalProperties": false
}
}
(I simplified to non-strict, because the playground validator is refusing despite tons of “additionalProperties”: false, a previous edit will show the allOf version…)
This is for the “tools=” parameter of a chat completions API call.
Although the usage will be self explanatory to the AI, when to use it is not, so description
fields should be placed in the function, that the function is the first step of finding company documentation - that must be the primary source of answers.
This is an approach to defining a function’s output for knowledge retrieval, with specific categories based on the type of information being retrieved.
The return would fulfilled by your code, and the enum values tuned to what categories you actually have content classified into.