Skip to content

AI Function Tools

This example assumes using Vectara; is in scope and apiKey contains your Vectara API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using var client = new VectaraClient(apiKey);

// Create AI function tools from the Vectara client.
// These can be passed to any IChatClient's ChatOptions.Tools.

// First, get a corpus key to configure the search tool.
ListCorporaResponse corporaResponse = await client.Corpora.ListAsync();

if (corporaResponse.Corpora is not { Count: > 0 })
{
    return;
}

var corpusKeys = corporaResponse.Corpora
    .Select(c => c.Key!)
    .ToArray();

// The search tool performs RAG queries across your corpora.
var searchTool = client.AsSearchTool(corpusKeys: corpusKeys, maxResults: 3);

// The list corpora tool discovers available document collections.
var listCorporaTool = client.AsListCorporaTool();

// The list LLMs tool shows available models for generation.
var listLlmsTool = client.AsListLLMsTool();

Console.WriteLine($"Created {3} AI function tools:");
Console.WriteLine($"  - {searchTool.Name}: {searchTool.Description}");
Console.WriteLine($"  - {listCorporaTool.Name}: {listCorporaTool.Description}");
Console.WriteLine($"  - {listLlmsTool.Name}: {listLlmsTool.Description}");