Skip to content

Commit

Permalink
Updated documentation for RAG
Browse files Browse the repository at this point in the history
  • Loading branch information
pranav-kural committed Jul 9, 2024
1 parent 0da2cac commit e890587
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 3 deletions.
38 changes: 37 additions & 1 deletion pages/chat-agent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,43 @@ import { Notice } from "../components/notice";

# Chat Agent

Chat Agent class provides the methods required to interact with the LLM model and generate responses to user queries. The class provides methods to generate responses and configure chat history.
Chat Agent class provides the methods required to interact with the LLM model and generate responses to user queries. Each chat agent instance can be configured to use specific LLM model, system prompt, chat prompt, tools and more.

Behind the scenes, each chat endpoint uses an instance of `ChatAgent` to process user queries and generate responses. However, you don't have to create a chat agent instance manually when defining a chat endpoint. Instead, you can provide the chat agent configuration directly in the chat endpoint configuration.

## Endpoint Chat Agent Config

When defining a new endpoint, you can configure which LLM model to use, the system prompt, chat prompt, tools and more, using the `chatAgentConfig` property.

```typescript copy
import { defineChatEndpoint } from "@oconva/qvikchat/endpoints";

// Define a chat endpoint with a specific chat agent configurations
defineChatEndpoint({
endpoint: "chat",
topic: "inventory data",
chatAgentConfig: {
model: "gemini15Pro",
modelConfig: {
version: "latest",
temperature: 0.5,
maxOutputTokens: 2048,
safetySettings: [
{
category: "HARM_CATEGORY_DANGEROUS_CONTENT",
threshold: "BLOCK_LOW_AND_ABOVE",
},
],
},
},
});
```

## Chat Agent Class

The `ChatAgent` class provides the methods required to interact with the LLM model and generate responses to user queries. You may, if you want to, use the chat agent class directly to generate responses to user queries.

Below documentation provides an overview of the `ChatAgent` class and its methods, but this knowledge is not required to define a chat endpoint.

## Types of Chat Agents

Expand Down
10 changes: 9 additions & 1 deletion pages/chat-endpoints/chat-endpoint-configurations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,15 @@ defineChatEndpoint({
chatAgentConfig: {
model: "gemini15Pro",
modelConfig: {
temperature: 0.9,
version: "latest",
temperature: 0.5,
maxOutputTokens: 2048,
safetySettings: [
{
category: "HARM_CATEGORY_DANGEROUS_CONTENT",
threshold: "BLOCK_LOW_AND_ABOVE",
},
],
},
},
enableAuth: true,
Expand Down
35 changes: 34 additions & 1 deletion pages/rag-guide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,40 @@ When creating a RAG enabled chat endpoint in QvikChat, we can easily perform bot

Let's take a look at an example below.

A RAG chat endpoint will require a data retriever that is can use to retriever context information when a user send a query, so lets create a retriever first.
A RAG chat endpoint will require a data retriever. You can either call the `getDataRetriever` method to get a retriever and pass this retriever instance as `retriever` to the chat endpoint, or you may use the `retrieverConfig` property of the chat endpoint to provide configurations for the retriever.

**Data Retriever Config**

Instead of creating a data retriever separately, you can also provide the data retriever configuration directly in the chat endpoint configuration.

```typescript copy
// Inventory Data chat endpoint with support for chat history, authentication, caching and RAG
defineChatEndpoint({
chatAgent: new ChatAgent({
agentTypeConfig: {
agentType: "rag",
topic: "Store Inventory Data",
},
useChatHistory: true,
}),
endpoint: "rag-chat-inventory",
enableChatHistory: true,
enableAuth: true,
apiKeyStore,
enableCache: true,
cacheStore,
enableRAG: true,
retrieverConfig: {
dataType: "csv",
filePath: "rag/knowledge-bases/inventory-data.csv",
generateEmbeddings: true,
},
});
```

**Data Retriever Instance**

If you want to create a data retriever separately, you can call the `getDataRetriever` method to get a retriever instance and pass this retriever instance as `retriever` to the chat endpoint. This method enables you to share the same retriever instance across multiple chat endpoints. If you are generating embeddings for data, then this would be the recommended approach, because you can generate embeddings once and share the retriever instance across multiple chat endpoints.

```typescript copy
// Index inventory data and get retriever
Expand Down
31 changes: 31 additions & 0 deletions pages/rag-guide/data-retrieval.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,34 @@ const inventoryDataRetriever = await getDataRetriever({
},
});
```

## Endpoint Retriever Config

Instead of creating a data retriever separately, you can also provide the data retriever configuration directly in the chat endpoint configuration. Data retriever will be created using the provided configuration when the chat endpoint is initialized.

Be mindful though that when sharing the same retriever configurations (for example, same data) and the `generateEmbeddings` flag is set to `true`, the data will be loaded and embeddings will be generated each time any chat endpoint using that retriever configuration is initialized. So, if you have multiple chat endpoints that will be sharing the same retriever config and you are generating embeddings for the data, it is recommended to create a retriever instance separately and share it across multiple chat endpoints as the `retriever` instance.

```typescript copy
// Inventory Data chat endpoint with support for chat history, authentication, caching and RAG
defineChatEndpoint({
chatAgent: new ChatAgent({
agentTypeConfig: {
agentType: "rag",
topic: "Store Inventory Data",
},
useChatHistory: true,
}),
endpoint: "rag-chat-inventory",
enableChatHistory: true,
enableAuth: true,
apiKeyStore,
enableCache: true,
cacheStore,
enableRAG: true,
retrieverConfig: {
dataType: "csv",
filePath: "rag/knowledge-bases/inventory-data.csv",
generateEmbeddings: true,
},
});
```

0 comments on commit e890587

Please sign in to comment.