Skip to content

Commit 8d46807

Browse files
authored
Merge pull request #14 from decisionfacts/db-connector-semantic-ai
Db structure db - semantic ai
2 parents 73bb361 + be939b1 commit 8d46807

30 files changed

+769
-156
lines changed

.env

+34-20
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,50 @@ EXTRACTED_DIR_PATH=
44

55
# Embeddings
66
EMBEDDING_TYPE=
7-
EMBED__MODEL_NAME=
7+
EMBED_MODEL_NAME=
88

99
# Connector
1010
CONNECTOR_TYPE=
11-
SHAREPOINT__CLIENT_ID=
12-
SHAREPOINT__CLIENT_SECRET=
13-
SHAREPOINT__TENANT_ID=
14-
SHAREPOINT__HOST_NAME=
15-
SHAREPOINT__SCOPE=
16-
SHAREPOINT__SITE_ID=
17-
SHAREPOINT__DRIVE_ID=
18-
SHAREPOINT__FOLDER_URL=
11+
SHAREPOINT_CLIENT_ID=
12+
SHAREPOINT_CLIENT_SECRET=
13+
SHAREPOINT_TENANT_ID=
14+
SHAREPOINT_HOST_NAME=
15+
SHAREPOINT_SCOPE=
16+
SHAREPOINT_SITE_ID=
17+
SHAREPOINT_DRIVE_ID=
18+
SHAREPOINT_FOLDER_URL=
1919

2020
# Indexer
2121
INDEXER_TYPE=
2222

2323
# Elasticsearch
24-
ELASTICSEARCH__URL=
25-
ELASTICSEARCH__USER=
26-
ELASTICSEARCH__PASSWORD=
27-
ELASTICSEARCH__INDEX_NAME=
28-
ELASTICSEARCH__SSL_VERIFY=False
24+
ELASTICSEARCH_URL=
25+
ELASTICSEARCH_USER=
26+
ELASTICSEARCH_PASSWORD=
27+
ELASTICSEARCH_INDEX_NAME=
28+
ELASTICSEARCH_SSL_VERIFY=False
2929

3030
# Qdrant
31-
QDRANT__URL=
32-
QDRANT__INDEX_NAME=
33-
QDRANT__API_KEY=
31+
QDRANT_URL=
32+
QDRANT_INDEX_NAME=
33+
QDRANT_API_KEY=
3434

35+
# IBM
36+
IBM_URL=
37+
IBM_API_KEY=
38+
IBM_PROJECT_ID=
3539

3640
# LLM
37-
LLM__MODEL=
38-
LLM__MODEL_NAME_OR_PATH=
39-
OPENAI_API_KEY=
41+
LLM_MODEL=
42+
LLM_MODEL_NAME_OR_PATH=
43+
OPENAI_API_KEY=
44+
45+
# SQL
46+
SQLITE_SQL_PATH=''
47+
48+
# MYSQL
49+
MYSQL_HOST=
50+
MYSQL_USER=
51+
MYSQL_PASSWORD=
52+
MYSQL_DATABASE=
53+
MYSQL_PORT=""

README.md

+76-23
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,43 @@ EXTRACTED_DIR_PATH= # default directory name 'extracted_dir'
2828

2929
# Connector (SharePoint, S3, GCP Bucket, GDrive, Confluence etc.,)
3030
CONNECTOR_TYPE="connector_name" # sharepoint
31-
SHAREPOINT__CLIENT_ID="client_id"
32-
SHAREPOINT__CLIENT_SECRET="client_secret"
33-
SHAREPOINT__TENANT_ID="tenant_id"
34-
SHAREPOINT__HOST_NAME='<tenant_name>.sharepoint.com'
35-
SHAREPOINT__SCOPE='https://graph.microsoft.com/.default'
36-
SHAREPOINT__SITE_ID="site_id"
37-
SHAREPOINT__DRIVE_ID="drive_id"
38-
SHAREPOINT__FOLDER_URL="folder_url" # /My_folder/child_folder/
31+
SHAREPOINT_CLIENT_ID="client_id"
32+
SHAREPOINT_CLIENT_SECRET="client_secret"
33+
SHAREPOINT_TENANT_ID="tenant_id"
34+
SHAREPOINT_HOST_NAME='<tenant_name>.sharepoint.com'
35+
SHAREPOINT_SCOPE='https://graph.microsoft.com/.default'
36+
SHAREPOINT_SITE_ID="site_id"
37+
SHAREPOINT_DRIVE_ID="drive_id"
38+
SHAREPOINT_FOLDER_URL="folder_url" # /My_folder/child_folder/
3939

4040
# Indexer
4141
INDEXER_TYPE="vector_db_name" # elasticsearch, qdrant
42-
ELASTICSEARCH__URL="elasticsearch_url" # give valid url
43-
ELASTICSEARCH__USER="elasticsearch_user" # give valid user
44-
ELASTICSEARCH__PASSWORD="elasticsearch_password" # give valid password
45-
ELASTICSEARCH__INDEX_NAME="index_name"
46-
ELASTICSEARCH__SSL_VERIFY="ssl_verify" # True or False
42+
ELASTICSEARCH_URL="elasticsearch_url" # give valid url
43+
ELASTICSEARCH_USER="elasticsearch_user" # give valid user
44+
ELASTICSEARCH_PASSWORD="elasticsearch_password" # give valid password
45+
ELASTICSEARCH_INDEX_NAME="index_name"
46+
ELASTICSEARCH_SSL_VERIFY="ssl_verify" # True or False
4747

4848
# Qdrant
49-
QDRANT__URL="<qdrant_url>"
50-
QDRANT__INDEX_NAME="<index_name>"
51-
QDRANT__API_KEY="<apikey>"
49+
QDRANT_URL="<qdrant_url>"
50+
QDRANT_INDEX_NAME="<index_name>"
51+
QDRANT_API_KEY="<apikey>"
5252

5353
# LLM
54-
LLM__MODEL="<llm_model>" # llama, openai
55-
LLM__MODEL_NAME_OR_PATH="" # model name
54+
LLM_MODEL="<llm_model>" # llama, openai
55+
LLM_MODEL_NAME_OR_PATH="" # model name
5656
OPENAI_API_KEY="<openai_api_key>" # if using openai
57+
58+
# SQL
59+
SQLITE_SQL_PATH="<database_path>" # sqlit db path
60+
61+
# MYSQL
62+
MYSQL_HOST="<host_name>" # localhost or Ip Address
63+
MYSQL_USER="<user_name>"
64+
MYSQL_PASSWORD="<password>"
65+
MYSQL_DATABASE="<database_name>"
66+
MYSQL_PORT="<port>" # default port is 3306
67+
5768
```
5869
Method 1:
5970
To load the .env file. Env file should have the credentials
@@ -72,6 +83,7 @@ from semantic_ai.config import Settings
7283
settings = Settings()
7384
```
7485

86+
# Un-Structure
7587
### 1. Import the module
7688
```python
7789
import asyncio
@@ -106,12 +118,53 @@ SCOPE = 'https://graph.microsoft.com/.default' # scope
106118
HOST_NAME = "<tenant_name>.sharepoint.com" # for example 'contoso.sharepoint.com'
107119

108120
# Sharepoint object creation
109-
connection = Sharepoint(client_id=CLIENT_ID,
110-
client_secret=CLIENT_SECRET,
111-
tenant_id=TENANT_ID,
112-
host_name=HOST_NAME,
113-
scope=SCOPE)
121+
connection = Sharepoint(
122+
client_id=CLIENT_ID,
123+
client_secret=CLIENT_SECRET,
124+
tenant_id=TENANT_ID,
125+
host_name=HOST_NAME,
126+
scope=SCOPE
127+
)
128+
```
129+
130+
# Structure
131+
132+
### 1. Import the module
133+
```python
134+
import asyncio
135+
import semantic_ai
136+
```
137+
138+
### 2. The database connection
139+
140+
#### Sqlite:
141+
```
142+
from semantic_ai.connectors import Sqlite
143+
144+
file_path= <database_file_path>
145+
146+
sql = Sqlite(sql_path=file_path)
147+
```
148+
149+
#### Mysql:
114150
```
151+
from semantic_ai.connectors import Mysql
152+
153+
sql = Mysql(
154+
host=<host_name>,
155+
user=<user_name>,
156+
password=<password>,
157+
database=<database>,
158+
port=<port_number> # 3306 is default port
159+
)
160+
```
161+
162+
### 3. To generate the answer from db using retrieval LLM model.
163+
```
164+
query = ""
165+
search_obj = await semantic_ai.db_search(query=query)
166+
```
167+
115168
## Run in the server
116169
```shell
117170
$ semantic_ai serve -f .env
6.36 KB
Loading
7.34 KB
Loading
3.44 KB
Loading

docs/source/connectors.rst

-4
This file was deleted.

docs/source/connectors/index.rst

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@ Connectors
77
:maxdepth: 2
88
:hidden:
99

10-
sharepoint
10+
sharepoint
11+
sqlite
12+
mysql

docs/source/connectors/mysql.rst

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
MYSQL
2+
=====
3+
4+
.. figure:: https://github.com/decisionfacts/semantic-ai/blob/master/docs/source/_static/images/logo/mysql.png?raw=true
5+
:alt: Logo
6+
:align: left
7+
:width: 100px
8+
:target: https://www.office.com/
9+
10+
This documents covers how to interact with Mysql database using our library.
11+
12+
**Pre-requisites:**
13+
14+
Please make sure the credentials of Mysql DB.
15+
16+
**Setup:**
17+
18+
**To create a mysql connection using credentials**
19+
20+
Please setup the value to the following environment object
21+
22+
.. code-block:: python
23+
24+
MYSQL_HOST='<host>'
25+
MYSQL_USER='<user>'
26+
MYSQL_PASSWORD='<password>'
27+
MYSQL_DATABASE='<database>'
28+
MYSQL_PORT='<port>'
29+
30+
.. code-block:: python
31+
32+
from semantic_ai.connectors import Mysql
33+
34+
conn = Mysql(
35+
host='<host>',
36+
user='<user_name>',
37+
password='<password>',
38+
database='<database>',
39+
port="<6033>" # it's default port
40+
)
41+
cursor = await conn.connect_db()
42+
43+
**To generate the sql query from NLP text**
44+
45+
.. code-block:: python
46+
47+
from semantic_ai.nlp.prompt import Prompt
48+
49+
prompt = Prompt()
50+
prompt_res = await prompt.nlp_to_sql(data_base=cursor, normal_text="query")
51+
52+
**To get answer from NLP**
53+
54+
.. code-block:: python
55+
56+
data = json.loads(prompt_res)
57+
result = sql.execution(data)

docs/source/connectors/sqlite.rst

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
SQLITE
2+
======
3+
4+
.. figure:: https://github.com/decisionfacts/semantic-ai/blob/master/docs/source/_static/images/logo/Sqlite.jpeg?raw=true
5+
:alt: Logo
6+
:align: left
7+
:width: 100px
8+
9+
SQLite is an in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.
10+
SQLite is an embedded SQL database engine. Unlike most other SQL databases, SQLite does not have a separate server process. SQLite reads and writes directly to ordinary disk files.
11+
12+
This documents covers how to interact with SQLITE database using our library.
13+
14+
**Pre-requisites:**
15+
16+
Please make sure the accessible Sqlite DB path.
17+
18+
**Setup:**
19+
20+
**To create a sqlite connection using path**
21+
22+
.. code-block:: python
23+
24+
SQLITE_SQL_PATH = '<DB_PATH>'
25+
26+
.. code-block:: python
27+
28+
from semantic_ai.connectors import Sqlite
29+
30+
file_path = f'<DB_PATH>'
31+
sqlite = Sqlite(sql_path=file_path)
32+
conn = await sqlite.connect_db()
33+
34+
**To create natural language processing for normal text**
35+
36+
.. code-block:: python
37+
38+
from semantic_ai.nlp.prompt import Prompt
39+
40+
prompt = Prompt()
41+
prompt_res = await prompt.nlp_to_sql(data_base=conn, normal_text="query")
42+
43+
**To get answer from NLP**
44+
45+
.. code-block:: python
46+
47+
data = json.loads(prompt_res)
48+
result = sql.execution(data)

docs/source/index.rst

+2
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ Library Documentation
2626
vector_indexer
2727
llm
2828
llm/index
29+
nlp
30+
nlp/index
2931
semantic_search

docs/source/llm/index.rst

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
LLM Models
22
==========
33

4+
A Large Language Model (LLM) typically refers to advanced natural language processing models that are characterized by their size and complexity. These models are designed to understand and generate human-like text at a sophisticated level
5+
46

57
.. toctree::
68
:maxdepth: 2

docs/source/nlp/index.rst

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
NLP to Text
2+
===========
3+
4+
Natural language processing (NLP) is a machine learning technology that gives computers the ability to interpret, manipulate, and comprehend human language.
5+
6+
.. toctree::
7+
:maxdepth: 2
8+
:hidden:
9+
10+
prompt

docs/source/nlp/prompt.rst

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
Natural Language Processing
2+
===========================
3+
4+
.. figure:: https://github.com/decisionfacts/semantic-ai/blob/master/docs/source/_static/images/logo/NLP.png?raw=true
5+
:alt: Logo
6+
:align: left
7+
:width: 100px
8+
:target: https://www.office.com/
9+
10+
Natural language processing (NLP) is a machine learning technology that gives computers the ability to interpret,
11+
manipulate, and comprehend human language.
12+
13+
**Prompt:**
14+
15+
An artificial intelligence (AI) prompt is a mode of interaction between a human and a large language model that lets
16+
the model generate the intended output. This interaction can be in the form of a question, text, code snippets or examples.
17+
18+
**Normal text to SQL:**
19+
20+
.. code-block:: python
21+
22+
async def nlp_to_sql(
23+
self,
24+
data_base: SQLDatabase,
25+
normal_text: str,
26+
prompt: str = None
27+
):
28+
29+
30+
The `nlp_to_sql()` function is used for generate the sql query from the normal text. It's return the sql response
31+
object. The function have three params first one is for get Database object next one is for get user query text and
32+
the last one for get prompt
33+
34+
.. code-block:: python
35+
36+
get_llm_chain()
37+
38+
i the prompt value is `None` then the default prompt will be apply.

0 commit comments

Comments
 (0)