> For the complete documentation index, see [llms.txt](https://docs.digit.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.digit.org/local-governance/v2.7/platform/configure-digit/services-overview/core-services/nlp-engine-service.md).

# NLP Engine Service

## Overview

In the existing version of the chatbot, for the PGR complaint creation feature, the user has to select the city from a drop-down menu by visiting the mSeva website. This significantly reduces user convenience as the user is required to constantly switch pages.\
To overcome the above inconvenience, the nlp-engine service is used. The service has an algorithm that uses ***fuzzy matching*** and ***pattern recognition*** to recognise the city provided by the user as input. Based on the user input, the cities having the highest match ratio with the input are being returned as the output list. A list comprising all the city names in English, Punjabi and Hindi was used as a reference tool for this service.

## Pre-requisites

Before you proceed with the documentation, make sure the following pre-requisites are met -

* *Python.*
* egov-mdms service is running and all the data related to the service are added to the MDMS repository.
* egov-running service is running.

## Key Functionalities

* Provides city fuzzy search feature which returns the list of cities having the highest match ratio with the input.
* City fuzzy search can support input data in *English, Hindi and Punjabi* language.
* Provides locality fuzzy search feature which returns the list of localities having the highest match ratio with the input.

| Environment Variables  | Description                                                                                                                |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| `MDMS_MODULE_NAME`     | Contains the module name of mdms required for nlp-engine.                                                                  |
| `CITY_MASTER`          | Contains the file name of mdms master file which contains the city names in various locale.                                |
| `CITY_LOCALE_MASTER`   | Contains the file name of mdms master file which contains the tenantid of the cities present in `CityNames.json` mdms file |
| `STATE_LEVEL_TENANTID` | Contains the state level tenantid                                                                                          |

## Interaction Diagram

![](/files/-MgiGjxA-Q27P9uMXqMe)

![](/files/-MgiGjxImx6mWr4GLOKh)

<figure><img src="/files/Tp6P09MirEp18tNGsZGT" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/1f0hf8Ssp4I5ywyVfA0Z" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/axBTVnQjyPtdTX9Jedtx" alt=""><figcaption></figcaption></figure>

## Deployment Details

1. Add mdms configs required for nlp-engine service ([mdms folder](https://github.com/egovernments/egov-mdms-data/tree/QA/data/pb/Chatbot)) and restart mdms service.
2. Deploy the latest version of nlp-engine service.
3. Whitelist the city and locality fuzzy search APIs.

## Integration

### Integration Scope

The nlp-engine service is used to locate user city and locality by using fuzzy string matching and pattern recognition.

### Integration Benefits

* Currently integrated into the chatbots for locating user city and locality for complaint creation use case.
* This feature functionality can be extended for the other entities and can be used for a fuzzy search of those different entities.

### Steps to Integration

1. To integrate, the host of nlp-engine service module should be overwritten in the helm chart.
2. `/nlp-engine/fuzzy/city` should be added as the fuzzy search endpoint for a city search.
3. `/nlp-engine/fuzzy/locality` should be added as the fuzzy search endpoint for locality search.

## Reference Docs

#### Doc Links <a href="#doc-links" id="doc-links"></a>

| Description | Link                                                                                                                                                                                                                               |
| ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| NLP Chatbot | [<img src="https://ssl.gstatic.com/docs/documents/images/kix-favicon7.ico" alt="" data-size="line">Documentation on NLP Chatbot](https://docs.google.com/document/d/1Z3IgyjlZzAchlMPfURmUrgVfcSqU316R_0Z6KNrRbLo/edit?usp=sharing) |

## API List

| Description                  | Link                                                          |
| ---------------------------- | ------------------------------------------------------------- |
| */nlp-engine/fuzzy/city*     | <https://www.getpostman.com/collections/9cd7600909d4ed16c173> |
| */nlp-engine/fuzzy/locality* | <https://www.getpostman.com/collections/9cd7600909d4ed16c173> |

*(Note: All the APIs are in the same postman collection therefore the same link is added in each row)*

[![Creative Commons License](https://i.creativecommons.org/l/by/4.0/80x15.png)](http://creativecommons.org/licenses/by/4.0/)*All content on this page by* [*eGov Foundation* ](https://egov.org.in/)*is licensed under a* [*Creative Commons Attribution 4.0 International License*](http://creativecommons.org/licenses/by/4.0/)*.*


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.digit.org/local-governance/v2.7/platform/configure-digit/services-overview/core-services/nlp-engine-service.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
