diff --git a/pages/chat-agent.mdx b/pages/chat-agent.mdx index b1ee63e..37de834 100644 --- a/pages/chat-agent.mdx +++ b/pages/chat-agent.mdx @@ -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 diff --git a/pages/chat-endpoints/chat-endpoint-configurations.mdx b/pages/chat-endpoints/chat-endpoint-configurations.mdx index 70d8cca..c96efd1 100644 --- a/pages/chat-endpoints/chat-endpoint-configurations.mdx +++ b/pages/chat-endpoints/chat-endpoint-configurations.mdx @@ -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, diff --git a/pages/rag-guide.mdx b/pages/rag-guide.mdx index ce00b20..046060e 100644 --- a/pages/rag-guide.mdx +++ b/pages/rag-guide.mdx @@ -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 diff --git a/pages/rag-guide/data-retrieval.mdx b/pages/rag-guide/data-retrieval.mdx index dac6b78..c5a51ac 100644 --- a/pages/rag-guide/data-retrieval.mdx +++ b/pages/rag-guide/data-retrieval.mdx @@ -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, + }, +}); +```