# Overview

**Sunbird AI Assistant** enables building Chat Bot based solutions powered by GenAI, that can provide easy access to timely, relevant and contextual information and suggestions to user queries. As part of Sunbird, it is a Digital Public Good (DPG) designed based on micro-services architecture and open for anyone to use.

The AI Assistant provides ability to understand and respond to queries in natural language (can support multiple languages). It analyses the overall context instead of just searching for exact keywords, leading to more precise and contextual responses.

The AI Assistant differs from generic AI chat bots like ChatGPT by its ability to train the bots on specific set of contents based on which the responses are provided. This would make the responses trustworthy and a lot more relevant to the use cases being implemented. &#x20;

As a DPG, it enables the following:

1. By being platform independent, DPG based solutions bring in the value of **eliminating vendor or product lock-in**. This is very important for long term sustainability of the solution.
2. Provides more **choices for implementation** and hence can enable **optimized solutions** for a given scenario.
3. Through open specifications and standards, it enables **interoperability**. This helps in easy stitching together of multiple solutions creating **multiplier value**.
4. Open license and an open ecosystem  around it, enables easy **evolvability**. The DPG can adapt and evolve over time, allowing for **continuous updates**. It would invite others to join and build solutions, thereby **enhancing its value proposition** and ensuring **ongoing relevance** and usefulness.
5. Apart from software, it enables creating a **common knowledge base** as part of the DPG in terms of guidelines, best practices and processes in rolling out solutions.
6. The open source software also **reduces initial time and cost** of creating solutions. &#x20;

A national scale adoption of Sunbird AI Assistant is [e-Jaadui Pitara](/functional-overview/use-cases/e-jaadui-pitara) by NCERT.    &#x20;


# Functional Overview

Following sections provide the functional overview of Sunbird AI Assistant:

1. [The Problem](/functional-overview/the-problem)&#x20;
2. [The Solution](/functional-overview/the-solution)
3. [Use cases](/functional-overview/use-cases)
4. [Capabilities](/functional-overview/capabilities)


# The Problem

<figure><img src="https://1392056186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5NW3631FGusFmDXiJi8A%2Fuploads%2F5eezWQk4Sc7c61W8Kpsz%2FAIAssistant-Problem1.png?alt=media&amp;token=b7b50d2d-1663-4043-ba7b-13edaa0ff807" alt="Citizens need access to accurate, trusted,  up-to-date information! …. often at scale. What disability benefits am I eligible for? I think my patient has COVID, what’s govt prescribed protocol?"><figcaption></figcaption></figure>

<figure><img src="https://1392056186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5NW3631FGusFmDXiJi8A%2Fuploads%2F0Ib7WxiktiYBm3hvr4rG%2FAIAssistant-Problem2.png?alt=media&amp;token=61f7dd21-a6e2-43c2-bdf2-bd80f2a40a1b" alt="Traditional sources of information overwhelm, confuse and even misinform the user!   Long detailed documents like handbooks, manuals. TV, radio programs, live casts at scheduled times. Call center, email helplines. Public forums (internet) and private conversations. Information Overload"><figcaption></figcaption></figure>


# The Solution

<figure><img src="https://1392056186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5NW3631FGusFmDXiJi8A%2Fuploads%2FloWCBCjxJ5xarcAZI93y%2FAIAssistant-Soln1.png?alt=media&amp;token=92b190be-9595-48b5-9d07-0e9b811b0253" alt="AI Assistant helps the citizens to access  just in time , context relevant information  from trusted sources. Note: It does not replace any existing ways of consuming information. It only provides an additional way, complimenting them."><figcaption></figcaption></figure>

<figure><img src="https://1392056186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5NW3631FGusFmDXiJi8A%2Fuploads%2FhpuLDjCniuZ24TLh8N4p%2FAIAssistant-Soln2.png?alt=media&amp;token=7c3a09bb-4147-48c7-b6b1-a29591f9f275" alt="Users can converse with AI Assistant in their choice of: Language: Supports conversations in multiple languages and dialects. Mode: Supports request and response in both chat and voice modes. Interface: Supports access through multiple apps and websites like Gov. app, WhatsApp, Telegram etc."><figcaption></figcaption></figure>


# Use Cases

Following are a set of use cases that AI Assistant can enable:

* A farmer getting information about multiple govt. schemes and programs
* A parent getting assistance on handling their child with special needs
* A teacher getting assistance on using a new teaching technique in her class
* A social worker getting suggestions on how she can help a victim of specific type of domestic violence&#x20;
* A healthcare professional getting information about preventing a new virus
* A citizen getting help about available Citizen Services&#x20;

A Smart Assistant solution to Teachers, Parents and Caregivers in the space of early education has been rolled out as [e-Jaadui Pitara](/functional-overview/use-cases/e-jaadui-pitara) by NCERT.


# e-Jaadui Pitara

e-Jaadui Pitara is a transformative initiative of Ministry of Education, Government of India, rolled out by NCERT for Foundational Stage learning.&#x20;

Following are the objectives of e-Jaadui Pitara:

1. Accelerate and amplify  the awareness, reach, and impact of the transformative idea of Jaadui Pitara as a symbol of NCF-FS
   * Increase awareness of Jaadui Pitara among teachers, parents and communities.
   * Democratise access to content to overcome the limitations of the physical Jaadui Pitara.
2. Digital technologies complement the physical Jaadui Pitara.&#x20;
   * Leverage multiple channels- e.g. computers, smartphones, feature phones, television and radio.
   * Leverage the potential of generative AI for relevant content creation and for language translation.
   * Leverage existing digital infrastructure to enable and empower the local ecosystem to participate and create content.&#x20;

<figure><img src="https://1392056186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5NW3631FGusFmDXiJi8A%2Fuploads%2FbZuPxmPGl6pwC4rf6hrc%2FeJP-1.png?alt=media&amp;token=2c2348bf-18ab-45c0-934e-2564523ec2c0" alt=""><figcaption></figcaption></figure>

<figure><img src="https://1392056186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5NW3631FGusFmDXiJi8A%2Fuploads%2FtRY77dwCyNxQlXsXkNot%2FeJP-2.png?alt=media&amp;token=5548dcf6-7a76-4883-ad96-6953784a7fec" alt=""><figcaption></figcaption></figure>

e-Jaadui Pitara consists of the following applications:

1. Mobile App
2. AI Bots - accessible through Mobile App, Telegram and WhatsApp
3. IVRS
4. Data and Dashboards
5. Website

{% embed url="<https://ejaaduipitara.ncert.gov.in/>" %}


# Capabilities

## Smart Assistant Bot(s)

* Different bots for different purposes, powered by GenAI, can be created.&#x20;
* The bots can
  * Answer user queries by retrieving information from given set of contents. The answers can provide information as well as suggest solutions to the queries.
  * Remember the message history (up to a configurable number of messages) and can respond based on the context of the conversation.&#x20;
  * Create stories for specific targeted users (like Indian children up to age 8) with a given context (like situation, character names etc.)
* The bots can be trained on a set of contents - makes it trustworthy.
* The bots can be accessed through multiple channels like WhatsApp, Telegram, Mobile/Web App etc.
* Bots can support multi-lingual and voice based communication by plugging in a third-party language service that provides translation, text to speech, speech to text capabilities for the required languages.

**Note** that following are **NOT** currently supported by Smart Assistant Bots

1. Answer for every question is always generated afresh. There is no caching of the question and answers. Hence, even if the same question is asked more than once, each time GenAI service is used to generate answer and hence may get different answers for the same question.
2. The AI Assistant responses can only provide required information and suggestions based on the trained content. It cannot strike a general conversation with the user.&#x20;
3. User persona can only be broadly defined, such as - a student, a parent, a farmer etc. It is not be possible to be more specific like - users between 13 to 18 years old, users between 18-30 years old etc.   Responses can also be not personalized for each user.&#x20;
4. Considering the nature of GenAI, smart assistant bots are primarily targeted for adults only. Any use of the bots by children has to be strictly under an adult guidance.     &#x20;

## Reference Mobile and Web (PWA) apps

* Access and play a curated set of content (videos, documents)
* Create own playlists of content for easy access
* Access the Smart Assistant Bots

## Dashboard

Can create dashboard that shows usage metrics - such as total messages for different bots, number of plays etc.

**Note**: Smart Assistant Bots or Apps do not require any user login. They do not store any personally identifiable information.


# Technical Overview

Sunbird AI Assistant can be used to create solutions that help citizens access just-in-time, context-relevant information from trusted sources.&#x20;

To get the functional overview and possible use cases, refer to [Functional Overview](/functional-overview).

The Sunbird AI Assistant primarily consists of an AI-driven backend bot service and services to integrate with Telegram and WhatsApp that can be used to provide front-end access to the bot service.

This section provides a technical overview of Sunbird AI Assistant. It provides the details of the technology stack, high-level components, and APIs. It also provides links to the source code.


# Architecture

Below is a high-level diagram of the various components powering the AI Assistant.

<figure><img src="https://1392056186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5NW3631FGusFmDXiJi8A%2Fuploads%2Fl2DCXN1k34yfFJfRwi2I%2FAI-Assistant-ArchDiagram.png?alt=media&amp;token=0fd44061-f268-49da-a2cf-685100aeea56" alt=""><figcaption></figcaption></figure>

## Components

#### sakhi-api-service

This is the backend service that takes a question and generates a relevant answer using the RAG mechanism. The answers are based on the information in a set of ingested documents. The service has to be configured with the specific marqo indexes to retrieve the sections of relevant documents and the GenAI prompts to generate a response in the required form.

Code:&#x20;

{% embed url="<https://github.com/Sunbird-AIAssistant/sakhi-api-service>" %}

#### Ingest-Documents Script

Document ingestion into the Marqo vector database is done through the below standalone python script.&#x20;

{% embed url="<https://github.com/Sunbird-AIAssistant/sakhi-api-service/blob/main/index_documents.py>" %}

Details on how to run is available under “To ingest data to marqo” section in the below readme file:&#x20;

{% embed url="<https://github.com/Sunbird-AIAssistant/sakhi-api-service/blob/main/README.md>" %}

#### sakhi-telegram-unified-service

This is a webhook service that registers with Telegram Service to oer the bot flow in the Telegram client. This doesn’t have any APIs exposed to the consumers. The calls to this service are delegated through the Telegram Service.

Code:&#x20;

{% embed url="<https://github.com/Sunbird-AIAssistant/sakhi-telegram-unified-servicewhatsapp-bot>" %}

#### whatsapp-bot

This is a webhook service that registers with WhatsApp Gupshup Service to oer the bot flow in the WhatsApp client. This doesn’t have any APIs exposed to the consumers. The calls to this service are delegated through the WhatsApp Gupshup Service.

Code:&#x20;

{% embed url="<https://github.com/Sunbird-AIAssistant/whatsapp-bot>" %}


# Technology Stack

Below is the technology stack used for the implementation of the AI Assistant. AI Assistant primarily uses the RAG mechanism, powered by Marqo (for retrieval) and GenAI services to generate answers for the user's questions.

**Front End**

* Telegram (a Telegram Bot)
* WhatsApp (a WhatsApp business number)

**Backend**

* Python - Programming Language
* FastAPI - Web framework for building APIs with Python
* Marqo - Marqo is an end-to-end vector search engine. Vector generation, storage

  and retrieval are handled out of the box through API.
* Cloud Storage Services (Supported are OCI Object Storage & AWS Buckets)
* Frameworks
  * LangChain - Framework to simplify the creation of applications using large language models.
  * LlamaIndex - Flexible data framework for connecting custom data sources to large language models.
* For Telegram:
  * Telegram Service Wrapper - Webhook to receive the request from the user

    through a Telegram Bot and to respond with answers. The webhook is

    registered with the Telegram Service Provider.
  * Redis - In-memory data store for holding users language and bot selection
* For WhatsApp GupShup provider:
  * WhatsApp Service Wrapper - Webhook to receive the request from the user and to respond with answers. The webhook is registered with the WhatsApp Service Provider, which in this implementation uses Gupshup.
  * PostgreSQL - Used for storing the user's session, language selected and bot selection for WhatsApp.

### External Services

* GenAI Services - LLM for,
  * Text Generation
  * Supported ones are,
    * OpenAI (GPT4) with Moderation
    * Azure OpenAI (GPT4) with Moderation
* Language Services for,
  * Language Translation
  * Speech to Text
  * Text to Speech
  * Supported ones are,
    * Bhashini Dhruva
    * EkStep Dhruva
    * Google Language Services
* Telemetry - Log events are getting captured for
  * api\_access
  * api\_call

### Other Tools / Services

* Docker
* Cloud Infrastructure - Supported ones are,
  * OCI
  * AWS

### Dependencies

List of external libraries used: <https://github.com/Sunbird-AIAssistant/sakhi-api-service/blob/main/requirements-prod.txt>


# Get Started with AI Assistant

### Quick-links to start with AI Assistant development

[**Key Steps to role out an AI Assistant Solution**](/get-started-with-ai-assistant/key-steps-to-role-out-an-ai-assistant-solution)

#### [Pre-requisites](/get-started-with-ai-assistant/pre-requisites)

#### [Installation](/get-started-with-ai-assistant/installation)

#### [Data Ingestion Process](/get-started-with-ai-assistant/data-ingestion-process)

#### [Configuration](/get-started-with-ai-assistant/configuration)

#### [APIs](/get-started-with-ai-assistant/apis)


# Key Steps to role out an AI Assistant Solution

Implementing a successful AI assistant solution requires careful planning and execution. Follow the below steps:

1. Identify the cloud service provider in which the AI Assistant Services needs to be installed.
2. Identify the Language AI Services and GenAI services to be used and procure licenses if any.
3. Identify the Sources of Information to be ingested and get access to it.
   * Types of documents to be ingested (documents, videos, and audio)
   * Optimizing or fine-tuning the ingestion process to work with the supplied information.
   * Different contexts/personas that will be using the data and the number of indexes to be created.
4. Fine-tune the retrieval configurations as appropriate
5. Optimize and fine-tune the GenAI prompts based on the use case
   * Prompt configuration for different contexts/personas
6. If the client interface includes Telegram, creation of the bot and configuring it
7. If the client interface includes Mobile App, developing and configuring the mobile app as appropriate.
8. If the client interface includes WhatsApp,&#x20;
   * Identify the service provider and develop service as per the provider
   * Sunbird AI Assistant comes with a default interface for Gupshup. If you have an existing service, then it can be used and configured to the account


# Pre-requisites

### Pre-requisites

Before running installation, ensure the following:

1. Have a cloud account ready with administrative access and have the secret access key and access key ID handy.
2. Administrative credentials details will be required and to be provided while running the installation script.
3. In case the bot service needs to be enabled through Telegram, you will need to create a telegram bot and secure public domain to configure webhook URL and add the details for the bot in the configuration (global-values.yaml) file.
4. Refer to configuration (global-values.yaml) file and update each environment variable with the required values.
5. Register the domain, add the TXT records in DNS mappings and generate the certificates, private key, domain and add that in the configuration (global-values.yaml) file.
6. Please note, global-cloud-values.yaml will be auto-generated during installation with terraform in the path ./helmcharts. if you have any file name as global-cloud-values.yml file in the same path please remove it.


# Installation

## Installer

Here is the link for the [installer](https://github.com/Sunbird-AIAssistant/ai-bot-installer).

Once the pre-requisites are satisfied, run the installation script (install\_on\_aws.sh).

{% hint style="info" %}
Check for your cloud specific installation script. The above one is for the AWS which is the default one.
{% endhint %}

## Load Balancer Configuration

After completing the provisioning process, log in to your cloud account. Then, map the load balancer DNS to your domain by updating the CNAME records in the DNS settings.

## WebHook for Telegram Client

To set the BOT webhook, use the below curl:&#x20;

```sh
curl --location 'https://api.telegram.org/bot{BOT_TOKEN_HERE}/setWebhook'
--header 'Content-Type: application/json'
--data '{"url": "{DOMAIN_URL_HERE}/api/webhook/telegram"}'
```

{% hint style="info" %}
Replace the `{BOT_TOKEN_HERE}` and `{DOMAIN_URL_HERE}/api/webhook/telegram` with the actual values.
{% endhint %}

## Accessing the Telegram Wrapper Service

To access the telegram-unified service externally, hit the URL: `https://<domain_name>/api/webhook/telegram`

### Manual Installation Steps:

1. [Sakhi API Service](https://github.com/Sunbird-AIAssistant/sakhi-api-service?tab=readme-ov-file#getting-started)
2. [Telegram Service ](https://github.com/Sunbird-AIAssistant/sakhi-telegram-unified-service?tab=readme-ov-file#sakhi-telegram-unified-bot-service)
3. [WhatsApp Service](https://github.com/Sunbird-AIAssistant/whatsapp-bot?tab=readme-ov-file#getting-started)


# Data Ingestion Process

After completing the installation, follow these steps to index all contents related to a specific use case:

### Release 3.0.0

1. Install Python on the machine where the files need to be ingested.
2. Clone Git Repo from [https://github.com/Sunbird-AIAssistant/sakhi-api-service](https://www.google.com/url?q=https://github.com/Sunbird-AIAssistant/sakhi-api-service\&sa=D\&source=editors\&ust=1712142234872409\&usg=AOvVaw23d0wT4lcVdCV9qqQUVOq8).
3. Go to the root directory and update the `.env` file with the necessary [vector store configuration](/components/sakhi-api-service/environment-variables) values.&#x20;
4. Run the following:&#x20;

{% code overflow="wrap" %}

```python
Step 1: pip install -r requirements-dev.txt 
Step 2: python3 index_documents.py --folder_path=<PATH_TO_INPUT_FILE_DIRECTORY> --fresh_index --chunk_size=1024 --chunk_overlap=100

# --fresh_index: Create a new index from scratch.
# --chunk_size: Divide the documents into chunks of 1024 characters. Default: 1024
# --chunk_overlap: Overlap each chunk by 100 characters for context. Default: 100
```

{% endcode %}

### Before Release 3.0.0

1. Install Python on the machine where the files need to be ingested.
2. Place the files to be indexed in a folder on the machine.
3. Download index\_documents.py and requirements-dev.txt file from [https://github.com/Sunbird-AIAssistant/sakhi-api-service](https://www.google.com/url?q=https://github.com/Sunbird-AIAssistant/sakhi-api-service\&sa=D\&source=editors\&ust=1712142234872409\&usg=AOvVaw23d0wT4lcVdCV9qqQUVOq8)
4. Run the following:&#x20;

<pre class="language-python" data-overflow="wrap"><code class="lang-python"><strong>Step 1: pip install -r requirements-dev.txt 
</strong><strong>Step 2: python3 index_documents.py --marqo_url=&#x3C;MARQO_URL> --index_name=&#x3C;MARQO_INDEX_NAME> --folder_path=&#x3C;PATH_TO_INPUT_FILE_DIRECTORY> --fresh_index
</strong></code></pre>

**Notes**:

1. Please run the commands via screen background, as it will take a couple of hours to run
2. “--fresh\_index” is to be used when you run the indexing for the first time or delete the existing index and freshly index it. If you want to append new files to the existing index, run it without --fresh\_index
3. For running without --fresh\_index, ensure your new files are kept in a new folder and the --folder\_path is pointed to only the new files.


# Configuration

### Configurations Configuring the Services

#### Functional configuration

#### sakhi-api-service

Sakhi Service enables configuration such as defining the indexes from where the documents are to be retrieved for a given context (parent, teacher, etc.) from Marqo, defining the bot behaviour through prompt, etc.&#x20;

A detailed set of configurations is captured here:&#x20;

{% embed url="<https://github.com/Sunbird-AIAssistant/sakhi-api-service/tree/main?tab=readme-ov-file#5-configuration-configini>" %}

**Configuration file:**

{% embed url="<https://github.com/Sunbird-AIAssistant/sakhi-api-service/blob/main/config.ini>" %}

#### **sakhi-telegram-unified-service**

Sakhi Telegram Service can be configured with the set of welcome messages to be shown to the user on Telegram, languages supported, set of bots supported (one bot for each context/persona) etc.

**Configuration file:**

{% embed url="<https://github.com/Sunbird-AIAssistant/sakhi-telegram-unified-service/blob/main/config.py>" %}

{% hint style="info" %}
**Note**: As currently these functional configuration files are inside the image that is created, the changes either need to be added when the image is built or needs to be overridden when the container is created.
{% endhint %}

### System configurations

The System configuration is specified in the respective repository as given below.

{% embed url="<https://github.com/Sunbird-AIAssistant/story-api-service?tab=readme-ov-file#5-conf>" %}

**sakhi-api-service**\
Refer to point#5 of the instructions given&#x20;

{% embed url="<https://github.com/Sunbird-AIAssistant/sakhi-api-service>" %}

**sakhi-telegram-unified-service**\
Refer to point#4 of the instructions given&#x20;

{% embed url="<https://github.com/Sunbird-AIAssistant/sakhi-telegram-unified-service>" %}

**whatsapp-bot**

{% embed url="<https://github.com/Sunbird-AIAssistant/whatsapp-bot?tab=readme-ov-file#3-configuration>" %}


# APIs

## sakhi-api-service&#x20;

It has the below APIs:

### v1/query

API is used for getting answers for user questions.

API details are available in this link

{% embed url="<https://github.com/Sunbird-AIAssistant/sakhi-api-service?tab=readme-ov-file#post-v1query>" %}

### **v1/chat**

API is used in engaging conversation with the user, users chat history is preserved.

API details are available in this link

{% embed url="<https://github.com/Sunbird-AIAssistant/sakhi-api-service?tab=readme-ov-file#post-v1chat>" %}


# Bot Creation 101

Here is the list of steps to install and configure the services:

1. [Install the services](/get-started-with-ai-assistant/installation)
2. [Ingest Data and create an Index](/get-started-with-ai-assistant/data-ingestion-process)
3. [Configure a new bot in the Sakhi API service](https://drive.google.com/file/d/1OvNvmJawDpgSW3Xkunqrkc6fY53ZIlXR/view)
4. Integrate the Sakhi API service with a front-end app:
   1. [WhatsApp](/faqs#how-to-configure-a-new-bot-in-whatsapp)
   2. [Telegram](/faqs#how-to-configure-a-new-bot-in-telegram)


# Components


# Sakhi API Service


# Environment Variables

Sakhi API service supports different environment variables to configure your instance. You can specify the following variables in the `.env` file inside the `root` folder. Refer to the [<mark style="color:purple;">**.env.example**</mark>](https://github.com/Sunbird-AIAssistant/sakhi-api-service) file.<br>

| Variable                 | Description                                            | Type                                  | Default      |
| ------------------------ | ------------------------------------------------------ | ------------------------------------- | ------------ |
| SERVICE\_ENVIRONMENT     | Name of the application instance                       | String                                | `dev`        |
| LOG\_LEVEL               | It's used to define  the level of logs to be captured. | Enum String: `error`, `info`, `debug` | `info`       |
| CONFIG\_INI\_PATH        | Path of config.ini file                                | String                                | `config.ini` |
| REDIS\_HOST              | Redis host URL                                         | String                                | `localhost`  |
| REDIS\_PORT              | Redis port number                                      | Number                                | `6379`       |
| REDIS\_DB                | Redis index                                            | Number                                | `0`          |
| TELEMETRY\_ENDPOINT\_URL | Telemetry service host URL                             | String                                | -            |
| TELEMETRY\_LOG\_ENABLED  | Used to enable/disable telemetry logging.              | Enum String: `true`, `false`          | `true`       |

### LLM

A chat model is a language model that uses chat messages as inputs and returns chat messages as outputs.\
Sakhi API service currently supports 3 LLM types:

1. [OpenAI](#openai)
2. [Azure OpenAI](#azure-openai)
3. [Ollama](#ollama)

These LLMs can be configured with the following env variables:

#### OpenAI

```markdown
LLM_TYPE=openai
OPENAI_API_KEY=<openai_key>
GPT_MODEL=<model_name>
```

#### **Azure OpenAI**

```markdown
LLM_TYPE=azure
AZURE_OPENAI_ENDPOINT=<azure_openai_endpoint_url>
AZURE_OPENAI_API_KEY=<azure_openai_key>
OPENAI_API_VERSION=<azure_openai_api_version>
AZURE_MODEL=<azure_deployment_model>
```

#### **Ollama**

```markdown
LLM_TYPE=ollama
OLLAMA_API_ENDPOINT=<ollama_endpoint_url>
LLM_MODEL=<model_name>
```

{% hint style="info" %}
If no env variables are specified, the service will throw the runtime exception.
{% endhint %}

For more information, Please refer to [LLM](/components/sakhi-api-service/pluggability-of-llm-chat-model) page.

### Storage

Storage is used for storing audio files when the user wants output as audio. Users should specify a configuration option, like BUCKET\_TYPE, to choose between different cloud provider services such as AWS S3, OCI, or GCP.

Here's the list of storage available to use in the Sakhi API Service:

1. [OCI](#oci-oracle)
2. [AWS](#aws-amazon)
3. [GCP](#gcp-google)

#### OCI (Oracle)

```markdown
BUCKET_TYPE=oci
BUCKET_ENDPOINT_URL=<oci_bucket_endpoint_url>
BUCKET_REGION_NAME=<oci_bucket_region_name>
BUCKET_NAME=<oci_bucket_name>
BUCKET_SECRET_ACCESS_KEY=<oci_bucket_access_key_id>
BUCKET_ACCESS_KEY_ID=<oci_bucket_access_key_id>
```

#### **AWS (Amazon)**

```markdown
BUCKET_TYPE=aws
BUCKET_REGION_NAME=<aws_bucket_region_name>
BUCKET_NAME=<aws_bucket_name>
BUCKET_SECRET_ACCESS_KEY=<aws_bucket_secret_access_key>
BUCKET_ACCESS_KEY_ID=<aws_bucket_access_key_id>
```

#### **GCP (Google)**

```markdown
BUCKET_TYPE=gcp
BUCKET_NAME=<gcp_bucket_name>
GCP_CONFIG_PATH=<gcp_application_credential_path>
```

{% hint style="info" %}
If no env variables are specified, the service will throw the runtime exception.
{% endhint %}

### Translation

Sakhi API service currently supports 3 translation services and can be configured with the following env variables:

1. [Bhashini Dhruva](#bhashini-dhruva)
2. [Ekstep Dhruva](#ekstep-dhruva)
3. [Google ](#google)

#### **Bhashini Dhruva**

```markdown
TRANSLATION_TYPE=bhashini
BHASHINI_ENDPOINT_URL=<bhashini_api_endpoint_url>
BHASHINI_API_KEY=<bhashini_api_key>
```

#### **Ekstep Dhruva**

```markdown
TRANSLATION_TYPE=dhruva
BHASHINI_ENDPOINT_URL=<bhashini_api_endpoint_url>
BHASHINI_API_KEY=<bhashini_api_key>
```

#### **Google**

```markdown
TRANSLATION_TYPE=google
GCP_CONFIG_PATH=<gcp_application_credential_path>
```

{% hint style="info" %}
If no env variables are specified, the service will throw the runtime exception.
{% endhint %}

### Vector Store

A vector store or vector database refers to a type of database system that specializes in storing and retrieving high-dimensional numerical vectors. These stores are designed for efficient management and indexing of vectors, enabling fast similarity searches.

Here is the list of vector stores/databases available to use in the Sakhi API Service:

1. [Marqo](#marqo)

#### **Marqo**

```shellscript
VECTOR_STORE_TYPE=marqo
VECTOR_STORE_ENDPOINT=http://localhost:8882
EMBEDDING_MODEL=flax-sentence-embeddings/all_datasets_v4_mpnet-base
VECTOR_COLLECTION_NAME=<vector_collection_name>
```

{% hint style="info" %}
If no env variables are specified, the service will throw the runtime exception.
{% endhint %}

For more information, Please refer to [Vector Store](/components/sakhi-api-service/pluggability-of-vector-store) page.


# Pluggability of LLM Chat Model

In this guide, we will learn how to plugin a new chat model client.  The plugin needs to extend/adhere to `BaseChatModel` of Langchain framework. Hence,  you can refer to the [langchain's LLM chat model integration page](https://python.langchain.com/v0.1/docs/integrations/chat/).

If you don't find your LLM chat model client on the above link, please refer to[ this link](https://python.langchain.com/v0.1/docs/modules/model_io/chat/custom_chat_model/) to create your custom LLM chat client by extending `BaseChatModel`&#x20;

A chat model is a language model that uses chat [messages](https://python.langchain.com/v0.1/docs/modules/model_io/chat/custom_chat_model/#messages) as inputs and returns chat messages as outputs.&#x20;

You can seamlessly leverage it within existing Sakhi API workflows with minimal code changes.

### Interface <a href="#base-chat-model" id="base-chat-model"></a>

The `BaseChatClient`  class has the below method to implement and returns an instance of [`BaseChatModel`](https://python.langchain.com/v0.1/docs/modules/model_io/chat/custom_chat_model/#base-chat-model) representing the specific Chat model client.

| Method/Property | Description                                                                                                        | Required/Optional |
| --------------- | ------------------------------------------------------------------------------------------------------------------ | ----------------- |
| get\_client     | Takes LLM model name as string  and required additional arguments, and returns an instance of specific Chat model. | Required          |

### Implementation <a href="#implementation" id="implementation"></a>

Let's say we create a `YourChatClient` class inheriting from `BaseChatClient`  using the chat model client provided by Langchain (in the link mentioned above).  You must implement `get_client` method to instantiate `YourChatClient` with the specified model and additional arguments.

Add the necessary environment variables to the `.env` file. `LLM_TYPE` is to be defined mandatorily. LLM chat model specific environment variables (Ex: API\_KEY) are also to be mentioned.&#x20;

{% code title="env" %}

```
LLM_TYPE=<your_chat_model_name>
```

{% endcode %}

Now go to the `llm`folder and create a file named: `your_chat_model_name.py`

{% code title="your\_chat\_model\_name.py" %}

```python
import os
from typing import Any

from langchain.chat_models import <LangchainChatModelClient>
from llm.base import BaseChatClient

class YourChatClient(BaseChatClient):
    """
    This class provides a chat interface for interacting with <LangchainChatModelClient>.
    """
    def get_client(self, model:str, **kwargs: Any) -> <LangchainChatModelClient>:
        """
        This method creates and returns a <LangchainChatModelClient> instance.

        Args:
            model (str, optional):  chat model to use.
            **kwargs: Additional arguments to be passed to the <LangchainChatModelClient> constructor.
 
        Returns:
            An instance of the <LangchainChatModelClient> class.
        """
        return LangchainChatModelClient(model=model, **kwargs)
```

{% endcode %}

{% hint style="info" %}
**`<LangchainChatModelClient>`** should be one of the LLM chat model clients mentioned [here](https://python.langchain.com/v0.1/docs/integrations/chat/).
{% endhint %}

Go to the LLM folder and update `__init__.py` with the module lookup entry for `YourChatClient`.

{% code title="**init**.py" %}

```python
_module_lookup = {
    ...,
    "YourChatClient": "llm.<your_chat_model_name>"
}
```

{% endcode %}

Modify `env_manager.py` to import `YourChatClient`  and add a mapping for `YourChatClient` in the `self.indexes` dictionary.

{% code title="env\_manager.py" %}

```python
from llm import (
    ...,
    YourChatClient
)
```

{% endcode %}

<pre class="language-python" data-title="env_manager.py"><code class="lang-python"><strong>self.indexes = {
</strong>    "llm": {
        "class": {
            ...,
            "&#x3C;your_chat_model_name>": YourChatClient
        },
        "env_key": "LLM_TYPE"
    }
}
</code></pre>

This setup ensures that `YourChatClient` can be instantiated based on specific environment variables, effectively integrating it into the environment management system. The `self.indexes` the dictionary now includes a mapping where  `<your_chat_model_name>` corresponds to the `YourChatClient` class, and uses `"LLM_TYPE"` as the environment key.

### Example usage <a href="#example-usage" id="example-usage"></a>

```python
from env_manager import llm_class
```

{% code overflow="wrap" %}

```python
llm  = llm_class.get_client(model=<your_llm_model_name>)
result = llm.invoke("Tell me a game using two sticks")
print(result.content)

#The game you can play using two sticks is called Gilli Danda. This game originated in India and requires two sticks. The smaller stick should be an oval-shaped wooden piece known as Gilli and the longer stick is known as danda. The player needs to use the danda to hit the Gilli at the raised end, which then flips.
```

{% endcode %}

For more examples, please refer to [Langchain](https://python.langchain.com/v0.1/docs/integrations/chat/google_generative_ai/#streaming-and-batching).


# Pluggability of Cloud Storage

In this guide, we will learn how to plugin a new cloud storage wrapper by extending the `BaseStorageClass` interface.

&#x20;You can seamlessly leverage it within existing Sakhi API workflows with minimal code changes.

### Integration <a href="#implementation" id="implementation"></a>

Cloud storage is used for storing the response generated from LLM which is then converted to **audio format** using a translation util. Link of the audio response files will be used by clients connecting to sakhi-api-service for playing the response.

### BaseStorageClass <a href="#base-chat-model" id="base-chat-model"></a>

This `BaseStorageClass` class has below methods which are to be implemented mandatorily.

| Method/Property       | Description                                                        | Required/Optional |
| --------------------- | ------------------------------------------------------------------ | ----------------- |
| \_\_init\_\_          | Used to instantiate the storage account client                     | Required          |
| upload\_to\_storage   | Takes name of the file to be uploaded                              | Required          |
| generate\_public\_url | Takes name of the file for which the public url is to be generated | Required          |

### Implementation <a href="#implementation" id="implementation"></a>

Let's say we create a `YourStorageClass` class inheriting from `BaseStorageClass.` The class needs to implement the following methods \_\_init\_\_, upload\_to\_storage and generate\_public\_url.

Add the necessary environment variables to  `.env` file. `BUCKET_TYPE` is to be defined mandatorily.

```
BUCKET_TYPE=your_cloud
```

Now go to the 'storage' folder and create your plugin: `your_cloud.py`

{% code title="your\_cloud.py" %}

```python

from storage.base import BaseStorageClass


class YourBucketClass(BaseStorageClass):
    def __init__(self):
        your_client = # instantiate your client
        super().__init__(your_client)

    def upload_to_storage(self, file_name: str, object_name: Optional[str] = None) -> bool:
        # code to upload file to your cloud storage
        return True

    def generate_public_url(self, object_name: str) -> Union[tuple[str, None], tuple[None, str]]:
        try:
            public_url = # you code to fetch public url of the uploaded file
            return public_url, None
        except Exception as e:
            logger.error(f"Exception Preparing public URL: {e}", exc_info=True)
            return None, "Error while generating public URL"
```

{% endcode %}

Go to the 'storage' folder and update `__init__.py` with the module lookup entry for "YourBucketClass" and also for TYPE\_CHECKING.

```python
if TYPE_CHECKING:
    ...
    from storage.your_cloud import (
        YourBucketClass
    )

_module_lookup = {
    ...,
    "YourBucketClass": "storage.your_cloud"
}
```

Modify `env_manager.py` to import `YourStorageClass`  and add a mapping for `YourStorageClass` in the `self.indexes` dictionary.

```python
from storage import (
    ...,
    YourBucketClass
)
```

<pre class="language-python"><code class="lang-python"><strong>self.indexes = {
</strong>    "storage": {
        "class": {
            ...,
            "your_cloud": YourBucketClass
        },
        "env_key": "BUCKET_TYPE"
    }
}
</code></pre>

This setup ensures that `YourBucketClass` can be instantiated based on specific environment variables, effectively integrating it into the environment management system. The `self.indexes` the dictionary now includes a mapping where `"your_cloud"` corresponds to the `"YourBucketClass"` class and uses `"BUCKET_TYPE"` as the environment key.


# Pluggability of Transaltion service

In this guide, we will learn how to plugin a new translation service by extending the `BaseTranslationClass` interface.

&#x20;You can seamlessly leverage it within existing Sakhi API workflows with minimal code changes.

### Integration <a href="#implementation" id="implementation"></a>

Translation service is used for supporting multiple languages in Sakhi-api-service.

### BaseTranslationClass <a href="#base-chat-model" id="base-chat-model"></a>

This `BaseTranslationClass` class has below methods which are to be implemented mandatorily.

| Method/Property  | Description                                                  | Required/Optional |
| ---------------- | ------------------------------------------------------------ | ----------------- |
| \_\_init\_\_     | Method to initialise or define necessary variables           | Optional          |
| translate\_text  | This method translates a text string to another language.    | Required          |
| text\_to\_speech | This method converts text to speech in a specified language. | Required          |
| speech\_to\_text | This method converts speech from an audio file to text.      | Required          |

### Implementation <a href="#implementation" id="implementation"></a>

Let's say we create a `YourTranslationClass` class inheriting from `BaseTranslationClass.` The class needs to implement the following methods translate\_text, text\_to\_speech and speech\_to\_text.

Add the necessary environment variables to  `.env` file. `TRANSLATION_TYPE` is to be defined mandatorily.

```
TRANSLATION_TYPE=your_translation_service
```

Now go to the 'translation' folder and create your plugin '`your_translation_service.py`'. Provide the implementation for the abstract methods.&#x20;

{% code title="your\_translation\_service.py" %}

```python

from translation.base import BaseTranslationClass


class YourTranslationClass(BaseTranslationClass):

    def translate_text(self, text: str, source: str, destination: str) -> str:
        # code to translate text
        return translated_text

    def text_to_speech(self, language: str, text: str) -> Any:
        return base_64_decoded_audio
        
    def speech_to_text(self, audio_file: Any, input_language: str) -> str:
        return transcripted_text    
```

{% endcode %}

Go to the 'translation' folder and update `__init__.py` with the module lookup entry for "YourTranslationClass" and also for TYPE\_CHECKING.

```python
if TYPE_CHECKING:
    ...
    from translation.your_translation_service import (
        YourTranslationClass
    )

_module_lookup = {
    ...,
    "YourTranslationClass": "translation.your_translation_service"
}
```

Modify `env_manager.py` to import `YourTranslationClass`  and add a mapping for `YourTranslationClass` in the `self.indexes` dictionary.

```python
from translation import (
    ...,
    YourTranslationClass
)
```

<pre class="language-python"><code class="lang-python"><strong>self.indexes = {
</strong>    "translation": {
        "class": {
            ...,
            "your_translation_service": YourTranslationClass
        },
        "env_key": "TRANSLATION_TYPE"
    }
}
</code></pre>

This setup ensures that YourTranslationClass can be instantiated based on specific environment variables, effectively integrating it into the environment management system. The `self.indexes` the dictionary now includes a mapping where `"your_translation_service"` corresponds to the `"YourTranslationClass"` class and uses `"TRANSLATION_TYPE"` as the environment key.


# Pluggability of  Vector Store

This document outlines the steps for creating a custom vector store class that inherits from the provided `BaseVectorStore` interface.&#x20;

As we know, many LLM applications leverage vector stores to efficiently retrieve relevant information for generating responses. A vector store acts as a specialized database designed to store and retrieve high-dimensional vector representations of data, such as documents. These vectors capture the semantic meaning and relationships between concepts in the data.

### Understanding the Base Interface:

To create your own vector store, you need to extend the `BaseVectorStore` class and implement the following methods:

<table><thead><tr><th width="179">Method/Property	</th><th width="378">Description</th><th>Required/Optional</th></tr></thead><tbody><tr><td>get_client</td><td>An abstract method that subclasses must implement to retrieve the client object used to interact with the specific vector store backend (e.g., Pinecone, Faiss).</td><td>Required</td></tr><tr><td>chunk_list</td><td>Helper function that splits a document list into batches of a specified size.</td><td>Optional </td></tr><tr><td>add_documents</td><td>An abstract method for adding documents to the vector store. Subclasses implement their specific logic for document insertion.</td><td>Required</td></tr><tr><td>similarity_search_with_score</td><td>An abstract method for performing similarity search on the vector store. Subclasses implement their specific logic for retrieving similar documents and scores based on a query string.</td><td>Required</td></tr></tbody></table>

### Implementation <a href="#example" id="example"></a>

Let's implement a custom vector store `YourVectorStoreClass`  inheriting from `BaseVectorStore` that adds documents and returns relevant documents whose text contains the semantic meaning in the user query.

Create a new file named `<your_vector_store_name>.py` in the `vectorstores` folder to define the `YourVectorStoreClass` .

Here's a brief overview of how you'll implement the `YourVectorStoreClass`:

```python
from vectorstores.base import BaseVectorStore

class YourVectorStoreClass(BaseVectorStore):
    
    def get_client(self):
        # Implement logic to retrieve the client for your vector store backend
        pass

    def chunk_list(self, document_list, chunk_size):
        # Optional: Implement logic to chunk documents into batches
        pass

    def add_documents(self, documents, fresh_collection: bool = False):
        # Implement logic to generate embedding, add documents to your vector store and return document IDs
        pass

    def similarity_search_with_score(self, query, collection_name: str, k: int = 20):
        #Args:
            #query: The query string to search for.
            #collection_name: Name of the collection within the vector store to search in.
            #k: The maximum number of documents to fetch from the vector store (default: 20).
            
        # Implement logic to perform a similarity search and return results with scores
        pass
```

In this example, we implement the `YourVectorStoreClass`, which provides concrete implementations for the abstract methods defined in `BaseVectorStore`.

* **get\_client**: Retrieves the specific client used to interact with the vector store backend.
* **chunk\_list**: Optionally, splits documents into chunks for more manageable processing.
* **add\_documents**: Adds documents to the vector store.
* **similarity\_search\_with\_score**: Performs a similarity search and returns documents along with their similarity scores based on the query.

Go to the `vectorstores` folder and update `__init__.py` with the module lookup entry for `YourVectorStoreClass`.

{% code title="**init**.py" %}

```python
_module_lookup = {
    ...,
    "YourVectorStoreClass": "llm.<your_vector_store_name>"
}
```

{% endcode %}

Modify `env_manager.py` to import `YourVectorStoreClass`  and add a mapping in the `self.indexes` dictionary.

{% code title="env\_manager.py" %}

```python
from vectorstores import (
    ...,
    YourVectorStoreClass
)
```

{% endcode %}

<pre class="language-python" data-title="env_manager.py"><code class="lang-python"><strong>self.indexes = {
</strong>    "vectorstore": {
        "class": {
            ...,
            "&#x3C;your_vector_store_name>": YourVectorStoreClass
        },
        "env_key": "VECTOR_STORE_TYPE"
    }
}
</code></pre>

This setup ensures that `YourVectorStoreClass` can be instantiated based on specific environment variables, effectively integrating it into the environment management system. The `self.indexes` the dictionary now includes a mapping where **`customVector`** corresponds to the `YourVectorStoreClass`, and uses `VECTOR_STORE_TYPE` as the environment key.

### Configuration

Configure your environment variables in the `.env` file for connecting to the vector store.

{% code title=".env" %}

```
VECTOR_STORE_TYPE=<your_vector_store_name>
VECTOR_STORE_ENDPOINT=<vector_store_endpoint>
EMBEDDING_MODEL=<embedding_model_name>
VECTOR_COLLECTION_NAME=<collection_name>
```

{% endcode %}

### Example Usage

Here is an example of how to add and query documents using the `vectorstore_class`.

#### Adding/Appending Documents

<pre class="language-python"><code class="lang-python">from env_manager import vectorstore_class
from langchain.docstore.document import Document

<strong>fresh_collection = True
</strong>documents = [
    Document(page_content="Test one", metadata={}), 
    Document(page_content="Test two", metadata={}),
    Document(page_content="Test three", metadata={}),
]

documentIDs = vectorstore_class.add_documents(documents, fresh_collection)
print(documentIDs)  # Output: [1, 2, 3]
</code></pre>

#### Querying Documents

```python
query = "Test one"
collection_name = "test"
documents = vectorstore_class.similarity_search_with_score(query, collection_name, k=20)
print(documents)

# Expected output:
# [
#    (Document(page_content="Test one", metadata={}), 0.95),
#    (Document(page_content="Test two", metadata={}), 0.65),
#    (Document(page_content="Test three", metadata={}), 0.61)
#  ]
```

By following this structure, you can efficiently interact with your custom vector store, adding and querying documents as needed.


# Release Notes


# Release Convention

The release packages of Sunbird AI Assistant follow the Semantic Versioning convention.

The release packages are available through the [GitHub packages](https://github.com/orgs/Sunbird-AIAssistant/packages) under the respective repositories.


# 3.0.0 (Latest)

| Release Version | Date        |
| --------------- | ----------- |
| 3.0.0           | 15-May-2024 |

### Overview

#### Sunbird AI Assistant Packages: Release 3.0.0

We are excited to announce the release of **Sunbird AI Assistant** packages, version 3.0.0. Users are encouraged to upgrade to the latest version to benefit from enhanced features, improved stability, and comprehensive support.

### New Features

It contains the following features

* **sakhi-api-service**
  * Generalisation of code for integration with various LLMs. Adaptors are available for integrating  with OpenAI (GPT4) , Azure OpenAI (GPT4) and Ollama&#x20;
  * Generalisation of code for integration with various Vector stores/databases. Adaptor is available for integrating with Marqo.&#x20;
  * Changes to environment variables

<table><thead><tr><th width="260">Old Variable</th><th>New Variable</th><th>Comments</th></tr></thead><tbody><tr><td>MARQO_URL</td><td></td><td>deprecated with addition of below variables related to VectorDB generalisation.</td></tr><tr><td></td><td>VECTOR_STORE_TYPE</td><td>Vector database type. Example: 'marqo'</td></tr><tr><td></td><td>VECTOR_STORE_ENDPOINT</td><td>Vector DB connection URL</td></tr><tr><td></td><td>EMBEDDING_MODEL</td><td><strong>Sentence Transformer model</strong> name. Please note that only sentence transformer models are supported as of now. Example: 'flax-sentence-embeddings/all_datasets_v4_mpnet-base' </td></tr><tr><td></td><td>VECTOR_COLLECTION_NAME</td><td>Index/Collection name to which data will be stored to</td></tr><tr><td>OPENAI_TYPE</td><td>LLM_TYPE</td><td>Name changed for generalising</td></tr></tbody></table>

{% hint style="info" %}
While indexing documents to VectorDB, previous command <mark style="color:orange;">`python3 index_documents.py --marqo_url=<MARQO_URL> --index_name=<MARQO_INDEX_NAME> --folder_path=<PATH_TO_INPUT_FILE_DIRECTORY> --fresh_index`</mark> has been now updated to  <mark style="color:green;">`python3 index_documents.py --folder_path=<PATH_TO_INPUT_FILE_DIRECTORY> --fresh_index`</mark>
{% endhint %}

### Release Tags: (GitHub Packages) <a href="#release-tags" id="release-tags"></a>

#### [sakhi-api-service](https://github.com/Sunbird-AIAssistant/sakhi-api-service/pkgs/container/sakhi-api-service/215892532?tag=3.0.0) <a href="#question-set-editor" id="question-set-editor"></a>

#### &#x20;<a href="#question-set-editor" id="question-set-editor"></a>

### **Bug Fixes**

### **Open/Known Bugs**

### **Breaking Changes**

* Renaming / Refactoring the environment variables

### **Installation**

* Installation steps are same as before, one thing to ensure before installation is to check the environment variables as it has undergone refactoring as part of this release.

### **Build Tags**

[**sakhi-api-service**](https://github.com/Sunbird-AIAssistant/sakhi-api-service/releases/tag/release-3.0.0)


# 2.0.0

| Release Version | Date |
| --------------- | ---- |
| 2.0.0           |      |

### Overview

#### Sunbird AI Assistant Packages: Release 2.0.0

We are excited to announce the release of **Sunbird AI Assistant** packages, version 2.0.0. Users are encouraged to upgrade to the latest version to benefit from enhanced features, improved stability, and comprehensive support.

### New Features

It contains the following services

* **sakhi-api-service**
  * Enabling the chat APIs for conversational history
  * Generalising the language services to use either Dhruva Bhashini, Dhruva EkStep or Google Services
  * Generalising the AI Services to use either OpenAI (GPT4) or Azure OpenAI (GPT4)&#x20;
  * Renaming audience\_type to context as part of generalisation&#x20;
  * Build fixes in the Dockerfile
  * Changes to environment variables

<table><thead><tr><th width="260">Old Variable</th><th>New Variable</th><th>Comments</th></tr></thead><tbody><tr><td>N/A</td><td>TRANSLATION_TYPE</td><td>New variable</td></tr><tr><td>N/A</td><td>BUCKET_TYPE</td><td>New variable</td></tr><tr><td>N/A</td><td>OPENAI_TYPE</td><td>New variable</td></tr><tr><td>N/A</td><td>REDIS_HOST</td><td>New variable</td></tr><tr><td>N/A</td><td>REDIS_DB</td><td>New variable</td></tr><tr><td>N/A</td><td>REDIS_PORT</td><td>New variable</td></tr><tr><td>N/A</td><td>TOP_DOCS_TO_FETCH</td><td>New variable</td></tr><tr><td>N/A</td><td>CONFIG_INI_PATH</td><td>New variable</td></tr><tr><td>OCI_ENDPOINT_URL</td><td>BUCKET_ENDPOINT_URL</td><td>Name changed for generalising</td></tr><tr><td>OCI_REGION_NAME</td><td>BUCKET_REGION_NAME</td><td>Name changed for generalising</td></tr><tr><td>OCI_BUCKET_NAME</td><td>BUCKET_NAME</td><td>Name changed for generalising</td></tr><tr><td>OCI_SECRET_ACCESS_KEY</td><td>BUCKET_SECRET_ACCESS_KEY</td><td>Name changed for generalising</td></tr><tr><td>OCI_ACCESS_KEY_ID</td><td>BUCKET_ACCESS_KEY_ID</td><td>Name changed for generalising</td></tr><tr><td>gpt_model</td><td>GPT_MODEL</td><td>Name changed for generalising</td></tr></tbody></table>

* **sakhi-telegram-unified-service**
  * Enabling the chat feature as default option for Bot Interactions, that retains the conversation history
  * Renaming audienceType to context as part of generalisation
* **whatsapp-bot**
  * Enabling the chat feature as default option for Bot Interactions, that retains the conversation history
  * Renaming audienceType to context as part of generalisation

### Release Tags: (GitHub Packages) <a href="#release-tags" id="release-tags"></a>

#### [sakhi-api-service](https://github.com/Sunbird-AIAssistant/sakhi-api-service/pkgs/container/sakhi-api-service/207278223?tag=2.0.0) <a href="#question-set-editor" id="question-set-editor"></a>

#### [sakhi-telegram-unified-service](https://github.com/Sunbird-AIAssistant/sakhi-telegram-unified-service/pkgs/container/sakhi-telegram-unified-service/207260776?tag=2.0.0) <a href="#question-set-editor" id="question-set-editor"></a>

#### [whatsapp-bot](https://github.com/Sunbird-AIAssistant/whatsapp-bot/pkgs/container/whatsapp-bot/207267846?tag=2.0.0) <a href="#question-set-editor" id="question-set-editor"></a>

### **Bug Fixes**

### **Open/Known Bugs**

### **Breaking Changes**

* Renaming / Refactoring the environment variables
* Renaming audienceType to context as part of generalisation

### **Installation**

* Installation steps are same as before, one thing to ensure before installation is to check the environment variables as it has undergone refactoring as part of this release.

### **Build Tags**

[**sakhi-api-service**](https://github.com/Sunbird-AIAssistant/sakhi-api-service/releases/tag/release-2.0.0)

[**sakhi-telegram-unified-service**](https://github.com/Sunbird-AIAssistant/sakhi-telegram-unified-service/releases/tag/release-2.0.0)

[**whatsapp-bot**](https://github.com/Sunbird-AIAssistant/whatsapp-bot/releases/tag/release-2.0.0)


# 1.0.0

| Release Version | Date |
| --------------- | ---- |
| 1.0.0           |      |

### Overview

#### Sunbird AI Assistant Packages: Release 1.0.0

We are pleased to announce the official release of **Sunbird AI Assistant** packages, version 1.0.0. This version marks significant development efforts aimed at delivering an optimized and robust AI assistant experience. Users are encouraged to upgrade to the latest version to benefit from enhanced features, improved stability, and comprehensive support.

### New Features

It contains the following services:

* **sakhi-api-service**
  * The base version of API Service for the Q\&A capability
  * Document Ingestion process for indexing the documents
* **sakhi-telegram-unified-service**
  * The base version of Telegram wrapper for the interaction with the Bots
* **whatsapp-bot**
  * The base version of WhatsApp wrapper for the interaction with the Bots

### Release Tags: (GitHub Packages) <a href="#release-tags" id="release-tags"></a>

#### [sakhi-api-service](https://github.com/Sunbird-AIAssistant/sakhi-api-service/packages) <a href="#question-set-editor" id="question-set-editor"></a>

#### [sakhi-telegram-unified-service](https://github.com/Sunbird-AIAssistant/sakhi-telegram-unified-service/packages)

#### [whatsapp-bot](https://github.com/Sunbird-AIAssistant/whatsapp-bot/packages) <a href="#question-set-editor" id="question-set-editor"></a>

### **Bug Fixes**

### **Open/Known Bugs**

### **Installation**

### **Build Tags**


# Roadmap

Coming Soon...


# Contribution Guide

### Welcome Contributors&#x20;

We're thrilled you're interested in contributing to the Sunbird AI Assistant Building Block! As an open-source project in a fast-paced field, we welcome all contributions, from new features and improved infrastructure to better documentation and bug fixes.&#x20;

### Getting Started&#x20;

#### New to the Project?&#x20;

No worries! Get acquainted with our project by exploring the [documentation](https://ai-assistant.sunbird.org/).

#### Ways to Contribute&#x20;

There are many ways to get involved and make a difference. Here are some common areas where people contribute:&#x20;

* **Improve the Documentation:** Help us make the docs, including this one, even better! Your edits, suggestions, and additions are invaluable.&#x20;
* **Code, Fix Bugs, and Improve Infrastructure:** We welcome your coding expertise! Help us write new features, fix bugs, or improve our infrastructure.&#x20;
* **Integrate with Favourite Vendors or Tools:** Do you have a favourite tool or vendor you'd love to see integrated with Sunbird? Please share your knowledge and help us make it happen!&#x20;
* **Answer Usage Questions and Discuss Issues:** Help us build a strong community by answering user questions, discussing issues, and providing valuable insights.&#x20;

{% hint style="info" %}
It's essential to discuss significant contributions to our discussion forum before proceeding to ensure your work aligns with the project's goals and direction.
{% endhint %}

#### Discussions Forums&#x20;

We have a [Discussions](https://github.com/orgs/Sunbird-AIAssistant/discussions/categories/q-a) page where users can ask usage questions, discuss design decisions, and propose new features.&#x20;

If you can help answer questions, please do so! This will allow the maintainers to focus more on development and bug fixing.&#x20;

### Core Contributions&#x20;

We primarily accept contributions through pull requests. Here's what you need to know:&#x20;

* **Fork the Repository**: Create a fork of our repository on GitHub.&#x20;
* **Clone your Fork**: Clone your forked repository to your local machine.&#x20;
* **Make Changes**: Make your changes and write clear commit messages.&#x20;
* **Test your Changes**: Ensure your changes function properly and adhere to our coding standards.&#x20;
* **Push to your Fork**: Push your changes to your forked repository.&#x20;
* **Open a Pull Request**: Submit a pull request to our main repository.&#x20;

{% hint style="info" %}
Important: By issuing a Pull Request, you agree to allow the project owners to license your work under the terms of the License. &#x20;
{% endhint %}

#### Pull Request Checkpoints:&#x20;

* **Testing**: All pull requests should include thorough testing to guarantee functionality and avoid breaking existing features.&#x20;
* **Code Style**: Adhere to coding style guidelines to promote readability and maintainability for everyone.&#x20;
* **Clear Description**: Provide a clear and concise description of your changes in the pull request. This will help reviewers understand your contribution.&#x20;


# FAQs

Do you have a query, suggestion or bug you would like to discuss? Discuss in our [forum](https://github.com/orgs/Sunbird-AIAssistant/discussions).

<details>

<summary>What is Sunbird AI Assistant?</summary>

Sunbird AI Assistant is a building block of Sunbird that provides capabilities to build AI bot-related solutions. It is a DPG, a Digital Public Good, which is designed based on micro-services architecture and is open source.

</details>

<details>

<summary>What types of content can be ingested or indexed?</summary>

The following content format types are supported:

* Documents - PDF, DOCX, PPT, CSV, EPUB, TXT
* Videos - mp4
* Audios - mp3
* Images - JPEG, JPG, PNG

Note that all the contents should be in English language only.

</details>

<details>

<summary>What is the level of configurable customisation available?</summary>

Following are the different configurations supported:

1. GenAI service - Open AI, Azure Open AI
2. Language service - Bhashini, Google
3. Supported languages - This can be English and the set of Indian languages supported by Bhashini
4. Response types - Can be text, audio or both
5. Gen AI GPT Model value - Can be 3.5 or 4
6. Enable or disable telemetry events logging to Sunbird Telemetry service

</details>

<details>

<summary>How to add new documents to the index for AI bots to use?</summary>

Please check the data ingestion document:  [Data Ingestion Process](/get-started-with-ai-assistant/data-ingestion-process)

</details>

<details>

<summary>How to change the Welcome message or other static messages of a bot (in Mobile App, Telegram and WhatsApp)?</summary>

The configuration that applies to the static messages of Telegram and WhatsApp is explained in the document “[Sunbird AI Assistant - Technical Overview](https://www.google.com/url?q=https://docs.google.com/document/d/1dEIAOHu2chVVZYDmqaOSXxHTLcQLmxEKFKcPnETz3pg/edit?usp%3Dsharing\&sa=D\&source=editors\&ust=1712137078204887\&usg=AOvVaw0Nf-dbDI8Zs4rPa7nEoA7y)” under the section “[Configurations](https://www.google.com/url?q=https://docs.google.com/document/d/1dEIAOHu2chVVZYDmqaOSXxHTLcQLmxEKFKcPnETz3pg/edit%23heading%3Dh.5l6owyvsr9io\&sa=D\&source=editors\&ust=1712137078205181\&usg=AOvVaw35F02p6IIj33E-8J58ci1Z)”.

</details>

<details>

<summary>If the page numbers of the sources given in the bot replies are not matching with the page numbers in the documents, what could be the issue?</summary>

This typically is seen when there are pages in the document ingested that don't carry a page number. In these cases, you can cross-check the content against the page number and remove these pages before ingestion so that the ingestion script can correctly tag the page number against the content.

</details>

<details>

<summary>If the bot replies “I am not currently trained with relevant documents to provide a specific answer for your question” - what could be the possible reasons? How to validate it?</summary>

This is an expected behavior when the Bot is not able to find a relevant answer to the user’s question. In such cases, it politely declines to answer by providing the message. You can also cross-check the content by using text searches to see if you are able to find any close matches. Additionally, you can cross-check the logs by engaging the operations team to check what information is retrieved from Marqo and check the relevance of the content.

</details>

<details>

<summary>How can I support more languages in the bots?</summary>

The configuration that enables the languages for Telegram and WhatsApp “request.supported\_lang\_codes” is explained in the document “[Sunbird AI Assistant - Technical Overview](https://www.google.com/url?q=https://docs.google.com/document/d/1dEIAOHu2chVVZYDmqaOSXxHTLcQLmxEKFKcPnETz3pg/edit?usp%3Dsharing\&sa=D\&source=editors\&ust=1712137078205985\&usg=AOvVaw2DUsMM44nlCjiH6mMATCaF)” under the section “[Configurations](https://www.google.com/url?q=https://docs.google.com/document/d/1dEIAOHu2chVVZYDmqaOSXxHTLcQLmxEKFKcPnETz3pg/edit%23heading%3Dh.5l6owyvsr9io\&sa=D\&source=editors\&ust=1712137078206215\&usg=AOvVaw2wAF0zfmW7Vi_H4FGGtgcR)”. This section covers the configuration that helps with language enablement in all the services.

</details>

<details>

<summary>If I am not getting correct answers in an Indian language, what could be the problem?</summary>

If it is an audio query that you are doing, try repeating it again. Maybe because a certain word is not correctly pronounced or maybe due to some external noise, it is not able to detect the question well.\
For audio or text, you can also check to make sure that it is the language you have selected in which you have sent the question. For example, if you selected a language as Kannada and if your question is in Hindi, the system will not detect the question. You can recheck the language that you have previously selected or select the language again and submit your question.\
The other possibility is that there are no relevant answers to the question you have asked.

</details>

<details>

<summary>What is the difference between the AI Assistant and a normal search engine?</summary>

Unlike a traditional search engine, an AI Assistant can accept input in any language, understand context, and generate answers by collating information from different parts of the content. The AI Assistant allows users to input queries in their own language or vocabulary and provides answers based on context rather than just matching specific words.

</details>

<details>

<summary>What is the infrastructure required for running Sunbird AI Assistant?</summary>

The infrastructure depends on the scale. Following is the suggested cloud infrastructure to run Sunbird AI Assistant in production with a minimum load of 1000 users per day:

**Cloud Infra requirements:**

1. Number of VMs - 2
2. Size of VMs (size of memory, No of CPU cores and type of processor) - 4 CPU Core, 16 GB RAM, 60 GB Disk

Apart from cloud infrastructure following are required:

1. Access to Language Service like Bhashini
2. Access to GenAI service and Open AI or Azure Open AI is the currently supported GenAI

Refer to [Sunbird AI Assistant - Technical Overview](https://www.google.com/url?q=https://drive.google.com/drive/u/1/folders/1sBwJxUk2lwh-mz-qxkCoTX6U-uhcbD3N\&sa=D\&source=editors\&ust=1712137078214420\&usg=AOvVaw1Aaq11bypqULuO0uusJ_lW) document for the detailed architecture

</details>

| Infrastructure                                                              | Required specifications           |
| --------------------------------------------------------------------------- | --------------------------------- |
| Number of VMs                                                               | 2                                 |
| Size of VMs (size of memory, No of CPU cores and type of processor)         | 4 CPU Core, 16 GB RAM, 60 GB Disk |
| OS type \~ linux or windows or paid linux                                   | Ubuntu 22.04 LTS                  |
| No. of clusters                                                             | 1                                 |
| No of worker nodes                                                          | 2                                 |
| Size of worker node (size of memory, No of CPU cores and type of processor) | 4 CPU Core, 16 GB RAM, 60 GB Disk |
| Storage types \~ frequent access, infrequent access and archival            | Object storage buckets - 5 GB     |
| Replication criteria across different availability zones                    |                                   |
| Open AI subscription                                                        | 1                                 |
| Bhashini/Google translate subscription                                      | 1                                 |
| Domain name and SSL certs                                                   | 1                                 |
| Database managed service(s)                                                 | Managed Postgres service          |

<details>

<summary>What will be the cost for running Sunbird AI Assistant?</summary>

The cloud infrastructure would cost approximately Rs. 60K per month for a user base of 10,000 users per day, and open AI would cost approximately Rs. 4 per message.

If you access the bot's front end through WhatsApp, there would be an additional cost. It is approximately Rs. 0.3 per user per day.

For a large-scale deployment, Bhashini language services might also have some costs, which the Bhashini team must obtain.

</details>

<details>

<summary>How long will it take to setup Sunbird AI Assistant and run?</summary>

A minimal testing instance can be set up in half a day using one-click installer (available for AWS). It would take around two to three days if you install it from scratch.

</details>

<details>

<summary>What is the scale of Sunbird AI Assistant?</summary>

It can horizontally scale to any scale. It is only limited by the OpenAI token limit. OpenAI has a limit on the number of tokens that it can service within a given time.

</details>

<details>

<summary>How fast will the responses to messages be?</summary>

This depends on the latency of OpenAI and Bhashini services. It can take from 20 seconds to a minute to get the response.

</details>

<details>

<summary>Has Sunbird AI Assistant been adopted in any live use case?</summary>

Yes, it is adopted as part of eJaaduiPitara recently launched by the Ministry of Education. Leveraging the potential of Sunbird AI Assistant, three Bots are developed as part of My Jaadui Pitara.

1. **Story Generation Bot**: This generates stories as per the context given by the user.This is not a replacement for the traditional storytelling forms and skills, but it helps the user by creating contextual stories in the local language. It also helps with generating interesting questions related to the story that can be asked to children. This virtual assistant is trained on a collection of traditional Indian stories mentioned in the NCF, like Panchatantra, Hitopadesh and Jataka katha to start with.
2. **Parent Assistance Bot**: This enables Parents to understand and relate to the definitions, key concepts and principles of foundation stage learning, using examples and illustrations in their simple and contextual language. Additionally, it offers guidance on day-to-day activities such as suggesting content, teaching activities, and connecting day-to-day activities to learning outcomes. The Bot is trained to answer questions based on the information from a predefined set of policy documents, training manuals, guidebooks, etc- such as Unmukh, Jaadui Pitara Manual, NCF, etc.
3. **Teacher Assistance Bot**: This enables Teachers to ask questions on multiple topics related to foundational stage learning. It also offers guidance on day-to-day activities such as selecting content, teaching methods, assessments, connecting assessments to learning outcomes, and managing the classroom. The Bot is trained to answer questions based on the set of documents trained for the Parent bot, plus an additional set of documents that are only relevant to Teachers, such as NISHTHA course materials.

Following are a few work-in-progress use cases that are being worked on for adoption:

1. An assistant for children on Child Abuse
2. An assistant for citizens with information on government administrative processes

</details>

<details>

<summary>How to configure a new bot context in sakhi-api-service?</summary>

To configure a new bot context, you will have to add below configurations in 'config.ini' of **sakhi-api-service**. Let us look at it with an example where our context is "*test\_bot*" and the corresponding vector collection/index it should refer to is "*test\_documents\_collection*".&#x20;

1. Add context to index mapping in the below configuration to specify the vector db collection/index from which documents for the bot is to be fetched from.\
   ![](https://1392056186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5NW3631FGusFmDXiJi8A%2Fuploads%2F4JPgcSb4ocU3ZFbPrnx0%2Fimage.png?alt=media\&token=0c94a866-b3b4-477a-bcb3-e948e7a6fb8a)
2. Configure the bot context in 'supported\_context' for performing bot context validation. Incoming requests to API will be validated with the configured bot context. <br>

   <figure><img src="https://1392056186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5NW3631FGusFmDXiJi8A%2Fuploads%2FK9OvDl6hhROotzov4FKO%2Fimage.png?alt=media&amp;token=4166d09c-e789-4a73-8902-8293793104bc" alt=""><figcaption></figcaption></figure>
3. In order to handle bot specific queries from the user, configure 'enable\_bot\_intent' to 'true' and add 'bot\_prompt' which will contain information of your bot that you want to reply with.&#x20;

&#x20;      <img src="https://1392056186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5NW3631FGusFmDXiJi8A%2Fuploads%2F6dg9ylQkvPLkTsUkOAn8%2Fimage.png?alt=media&amp;token=a6641d18-6bb8-4673-b04e-96fd8483ae9f" alt="" data-size="original">

3. To generate answers for user queries, configure the 'activity\_prompt' which will have the steps to perform by LLM using the passed documents from vector db.

&#x20;     <img src="https://1392056186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5NW3631FGusFmDXiJi8A%2Fuploads%2FN0Qqjr283gJHbUbydiK0%2Fimage.png?alt=media&amp;token=e4dbe375-3907-4667-8c8c-f91903bffcd8" alt="" data-size="original">

</details>

<details>

<summary>How to configure a new bot in Telegram?</summary>

### Single Bot configuration

If you are using single bot under your Telegram bot channel, configure the 'context' value under the 'default' section for the bot in 'config.ini' of 'sakhi-telegram-unified-service'

![](https://1392056186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5NW3631FGusFmDXiJi8A%2Fuploads%2FIvXrnBO6uHRQQWUGeNsv%2Fimage.png?alt=media\&token=b055823e-eb81-4438-b32a-43de2368ae2c)

Default context information, 'default\_context\_selection',  is to be configured in all language files (ex: '**en.json**') under '**languages**' folder.

![](https://1392056186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5NW3631FGusFmDXiJi8A%2Fuploads%2F37nmaeyDUwL9QiZThbEZ%2Fimage.png?alt=media\&token=84b6fee5-9aed-4d24-9ebc-cddbf81159d0)

### Multiple Bots Configuration

Steps to configure multiple bots under your Telegram bot channel:

1. Go to '**BotFather'** in your Telegram application where you have created the channel
2. select '/mybots' and select the channel under which you wants to create bots.
3. Click on 'Edit Bot' button and the click on 'Edit Commands' button.
4. Add the list of commands to the channel. Example:\
   `select_language - user language selection`\
   `select_context - user bot context selection`

For both of the scenarios, necessary context information is to be configured in corresponding language file (ex: '**en.json**') under '**languages**' folder.

![](https://1392056186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F5NW3631FGusFmDXiJi8A%2Fuploads%2F6ZGEQ7E6TTUVmzXLgtLJ%2Fimage.png?alt=media\&token=f0debb4d-2523-49ce-959e-cc4a24d54a77)

</details>

<details>

<summary>How to configure a new bot in WhatsApp?</summary>

This guide describes how to configure a new bot for the WhatsApp application. We'll use the example of a "farmer\_bot" to illustrate the process.

**User Interface:**

Modify the initial screen where users choose bots. Include a new quick reply button labeled "Farmer Assistant" alongside the existing options (Story Sakhi, Parent Tara, Teacher Tara).

* Update the `bot_selection` section in your language file (e.g., `en.json`) located under `assets/language`.
* Add a new option object within the `options` array for "Farmer Assistant."
* Set the `title` to "Farmer Assistant" and the `postbackText` to "bot\_\_bot\_4" (assuming this is the new identifier for the farmer bot).

Here's an example of the updated JSON snippet:

{% code title="en.json" overflow="wrap" %}

```json
{
  "bot_selection": {
    "message": {
      "type": "quick_reply",
      "msgid": "bot",
      "content": {
        "type": "text",
        "header": "e-Jaadui Pitara",
        "text": "... (Welcome message content) ...\n\nPlease select below option to proceed",
        "caption": "Please select below option to proceed",
        "options": [
          {
            "type": "text",
            "id": "bot",
            "title": "Story Sakhi",
            "postbackText": "bot__bot_1"
          },
          {
            "type": "text",
            "id": "bot",
            "title": "Parent Tara",
            "postbackText": "bot__bot_2"
          },
          {
            "type": "text",
            "id": "bot",
            "title": "Teacher Tara",
            "postbackText": "bot__bot_3"
          },
          {
            "type": "text",
            "id": "bot",
            "title": "Farmer Assistant",
            "postbackText": "bot__bot_4"  // New postback text for Farmer Assistant
          }
        ]
      }
    }
  },
  ....
}
```

{% endcode %}

#### Individual Bot Configurations

Each bot (Story Sakhi, Parent Tara, Teacher Tara) has its own welcome message defining its capabilities and providing examples of prompts users can provide.

Let's configure the welcome message for Farmer Assistant as below:

{% code title="en.json" overflow="wrap" %}

```json
{
  "bot_selection": {
   ....
  "bot_1": { ... (Existing Story Sakhi configuration) ... },
  "bot_2": { ... (Existing Parent Tara configuration) ... },
  "bot_3": { ... (Existing Teacher Tara configuration) ... },
  "bot_4": {  // New welcome message section for Farmer Assistant
    "Welcome": {
      "message": {
        "type": "text",
        "text": "Welcome to Farmer Assistant! I can help you with various farming related tasks. Here are some examples:\n- Ask me about weather forecasts for the next week.\n- What are some good pest control methods for tomatoes?\n- Tell me about crop rotation techniques for corn.\n\nFeel free to ask me anything related to farming."
      }
    },
  }
}                                                                                              
```

{% endcode %}

**Note:** Remember to repeat this configuration process for all supported languages within their respective language files under the `assets/language` folder.

</details>


# Knowledge Base


# Best Practices

1. Providing a reference to sources in responses increases trustworthiness.
2. Work on the documents chunking strategy like keeping chunk size of 512/768/1024 with text overlap as 150/200 and verify the retrieval results efficiency for minimum of 30 queries.
3. Ensure your prompt has instructions to avoid responding to queries involving politics, political personalities, religion, caste, skin colour or any other sensitive topics. Perform a round of testing of the bot involving these corner cases.&#x20;
4. Put a disclaimer (in the bot welcome message or any other suitable place) stating that bot responses are from GenAI and may not be 100% accurate.&#x20;
5. Try different embedding models/sentence transformers to verify/improve indexing+retrieval efficiency. You can also refer to <https://huggingface.co/spaces/mteb/leaderboard>
6. Good to know: <https://huggingface.co/spaces/open-llm-leaderboard/open_llm_leaderboard> , <https://huggingface.co/spaces/lmsys/chatbot-arena-leaderboard>


# Indexing CSV Data

Page discusses about different approaches one can take for indexing csv data based on their use-case.

### Solution 1: Summarized Text in Vector Database

Process:

1. Generate a summary of each row in the CSV using an LLM.
2. Store the summarized text in a vector database.
3. Pass the user's query to the vector database to fetch the related information.

Pros:

* Semantic Search: Can handle natural language queries effectively, understanding the context and intent beyond keyword matching.
* Flexibility: Can deal with diverse and complex queries without requiring a predefined schema.
* Ease of Use: Users can ask questions in natural language, which is intuitive and user-friendly.

Cons:

* Resource Intensive: Generating summaries and maintaining a vector database can be resource-intensive in terms of computational power and storage.
* Performance: Vector similarity searches can be slower for very large datasets compared to traditional database queries.
* Dependency on Summarization Quality: The quality of search results depends heavily on the accuracy and completeness of the summaries generated by the LLM.

#### Use Cases:

#### Customer Support: For handling a wide range of queries from customers and retrieving relevant support articles or FAQs.

Sample CSV:

ticket\_id,issue,description

1,Login Issue,"User unable to log into account despite correct credentials."

2,Payment Failure,"Payment failed during checkout, transaction not completed."

3,Account Hacked,"User's account has been accessed by unauthorized persons."

4,Product Not Received,"User has not received the product even after the delivery date."

5,Refund Request,"User requested a refund for the returned product but has not received it."

Example User Queries:

1. "I can't log into my account even though my password is correct."
2. "My payment didn't go through during checkout."
3. "I think my account has been hacked."<br>

#### Document Management: In legal, academic, or corporate environments where documents need to be retrieved based on complex queries.

Sample CSV:

document\_id,title,summary

1,Contract Agreement,"A contract agreement between two parties outlining terms and conditions."

2,Research Paper,"A detailed study on the effects of climate change on marine life."

3,Legal Case,"A legal case involving patent infringement and intellectual property rights."

4,Policy Document,"A document detailing the company's new HR policies and procedures."

5,Technical Manual,"A manual providing technical specifications and usage instructions for a new software."

Example User Queries:

1. "Show me the document related to patent infringement."
2. "I need the research paper on climate change effects."
3. "Can you find the contract agreement document?"<br>

#### Content Recommendation: For recommending products, articles, or media based on natural language descriptions of user preferences or needs.

Sample CSV:

content\_id,title,description

1,The Great Gatsby,"A classic novel set in the Jazz Age that explores themes of wealth and excess."

2,Inception,"A science fiction film about a thief who enters people's dreams to steal secrets."

3,Introduction to Python,"A beginner's guide to programming in Python."

4,Healthy Eating,"An article about the benefits of a balanced diet and healthy eating habits."

5,Yoga for Beginners,"A guide to starting yoga practice, including basic poses and tips."<br>

Example User Queries:

1. "Recommend me a classic novel to read."
2. "I'm looking for a movie about dreams and reality."
3. "Do you have any articles on healthy eating?"

<br>

### Solution 2: SQL/NoSQL Database with LLM for Query Interpretation

Process:

1. Store the CSV data in a SQL/NoSQL database.
2. Use an LLM trained with few-shot examples to interpret the user's query and generate a corresponding database query.
3. Fetch records from the SQL/NoSQL database based on the interpreted query.

Pros:

* Performance: SQL/NoSQL databases are optimized for fast querying of structured data, making this solution more efficient for large datasets.
* Existing Infrastructure: Leverages existing database infrastructure, which many organizations already have in place.
* Structured Queries: Can provide more accurate results when the data is well-structured and indexed.

Cons:

* Complex Query Mapping: Translating natural language queries into accurate database queries can be challenging and may require extensive training and fine-tuning of the LLM.
* Less Flexible: May not handle very complex or abstract queries as well as a vector-based approach.
* Schema Dependency: Changes to the database schema may necessitate updates to the LLM's query interpretation logic.

Use Cases:

* Business Intelligence: Generating reports and insights from large datasets based on structured queries.

Sample CSV:

report\_id,department,metrics,period

1,Sales,"Total sales, revenue, profit margins",Q1 2023

2,HR,"Employee retention rate, new hires, turnover rate",Q1 2023

3,Marketing,"Ad spend, ROI, lead generation",Q1 2023

4,Finance,"Expenses, net income, cash flow",Q1 2023

5,IT,"System uptime, incident response time, new projects",Q1 2023

Example User Queries:

1. "Show me the sales report for Q1 2023."
2. "I need the HR metrics for the first quarter of 2023."
3. "What are the marketing KPIs for Q1 2023?"

<br>

* Inventory Management: Managing and querying inventory data where queries are typically structured around specific fields like product ID, location, etc.

Sample CSV:

product\_id,product\_name,quantity,location

1,Widget A,100,Warehouse 1

2,Gadget B,50,Warehouse 2

3,Device C,75,Warehouse 1

4,Tool D,20,Warehouse 3

5,Item E,10,Warehouse 2

Example User Queries:

1. "How many Widget A are in stock?"
2. "Give me the inventory details for Warehouse 2."
3. "What is the quantity of Device C?"

<br>

* Healthcare Records: Retrieving patient records or treatment histories based on specific attributes like patient ID, date, or diagnosis.

Sample CSV:

patient\_id,name,diagnosis,treatment,date

1,John Doe,Diabetes,Insulin Therapy,2023-06-01

2,Jane Smith,Hypertension,Medication,2023-06-02

3,Alan Brown,Asthma,Inhaler,2023-06-03

4,Emily Davis,Flu,Rest and Fluids,2023-06-04

5,Michael Johnson,Fracture,Cast and Physical Therapy,2023-06-05

<br>

Example User Queries:

1. "Fetch the medical record for John Doe."
2. "Show me all patients diagnosed with diabetes."
3. "Get the treatment details for the patient with a fracture."

<br>

#### Conclusion

Solution 1 is ideal for scenarios where the nature of the queries is complex, varied, and context-rich. It is well-suited for environments where users benefit from the flexibility and semantic understanding of natural language processing, such as customer support, document management, and content recommendation.

Solution 2 is better suited for environments where queries can be well-defined and mapped to a structured database schema. It is more efficient for large datasets and situations where performance and accuracy are critical, such as business intelligence, inventory management, and healthcare records.

#### Choosing the Right Solution

Solution 1 (Vector Database) is recommended if:

* You need to handle a wide variety of complex and semantically rich queries.
* User queries are often in natural language and require a high degree of contextual understanding.
* You have the computational resources to support vector database operations.

Solution 2 (SQL/NoSQL Database with LLM Query Interpretation) is recommended if:

* Queries are typically structured and can be mapped to specific database fields.
* You need high performance and efficiency for large datasets.
* You want to leverage existing database infrastructure and ensure accuracy through structured queries.

Ultimately, the choice depends on the specific requirements of your use case, including the nature of the queries, the structure of the data, and the performance considerations.

<br>


# Contact us

You can have discussions with the Sunbird AI Assistant community at [Sunbird-AIAssistant](<  https://github.com/orgs/Sunbird-AIAssistant/discussions>) discussion forum.


