Skip to content

Commit

Permalink
Merge pull request #614 from Bennu-Li/update_qa
Browse files Browse the repository at this point in the history
update qa-chatbot to Milvus2.0.0-rc5
  • Loading branch information
Bennu-Li authored Sep 1, 2021
2 parents 2f3bf44 + 70613de commit fd0e029
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 92 deletions.
13 changes: 6 additions & 7 deletions solutions/question_answering_system/question_answering.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"metadata": {},
"source": [
"# Question Answering System\n",
"In this example we will be going over the code used to build a question answering system. This example uses a modified BERT model to extract features from questions and Milvus to search for similar questions and answers. "
"In this example we will be going over the code used to build a question answering system. This example uses a modified BERT model to extract features from questions and Milvus to search for similar questions and answers. \n",
"\n",
"> This project based Milvus 2.0.0-rc5."
]
},
{
Expand All @@ -29,7 +31,7 @@
"\n",
"| Packages | Servers |\n",
"|- | - | \n",
"| pymilvus-orm==2.0.0rc1 | milvus 2.0.0 |\n",
"| pymilvus==2.0.0rc5 | milvus 2.0.0-rc5 |\n",
"| sentence_transformers | |\n",
"| psmysql | mysql |\n",
"| pandas | |\n",
Expand Down Expand Up @@ -146,10 +148,7 @@
"outputs": [],
"source": [
"#Connectings to Milvus, BERT and Postgresql\n",
"from pymilvus_orm import connections, utility\n",
"from pymilvus_orm.types import DataType\n",
"from pymilvus_orm.schema import FieldSchema, CollectionSchema\n",
"from pymilvus_orm.collection import Collection\n",
"from pymilvus import connections, FieldSchema, CollectionSchema, DataType, Collection, utility\n",
"import pymysql\n",
"\n",
"connections.connect(host='localhost', port='19537')\n",
Expand Down Expand Up @@ -454,4 +453,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
}
}
4 changes: 3 additions & 1 deletion solutions/question_answering_system/quick_deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

This project combines Milvus and BERT to build a question and answer system. This aims to provide a solution to achieve semantic similarity matching with Milvus combined with AI models.

> This project based Milvus2.0.0-rc5
## Data description

The dataset needed for this system is a CSV format file which needs to contain a column of questions and a column of answers.
Expand Down Expand Up @@ -163,4 +165,4 @@ After starting the service, Please visit `127.0.0.1:8000/docs` in your browser
iii. **Obtain answer**: Click any of the similar questions obtained in the previous step, and you'll get the answer.



This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PyMySQL
uvicorn
numpy
pymilvus-orm==2.0.0rc1
pymilvus==2.0.0rc5
fastapi
python-multipart
pandas
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import sys
from pymilvus_orm import connections
from pymilvus_orm.types import DataType
from pymilvus_orm.schema import FieldSchema, CollectionSchema
from pymilvus_orm.collection import Collection
from pymilvus import connections, FieldSchema, CollectionSchema, DataType, Collection, utility

from config import MILVUS_HOST, MILVUS_PORT, VECTOR_DIMENSION, METRIC_TYPE
from pymilvus_orm import utility
from logs import LOGGER



class MilvusHelper:
def __init__(self):
try:
Expand All @@ -25,15 +23,15 @@ def set_collection(self, collection_name):
else:
raise Exception("There has no collection named:{}".format(collection_name))
except Exception as e:
LOGGER.error("Failed to load data to Milvus: {}".format(e))
LOGGER.error("ERROR: {}".format(e))
sys.exit(1)

# Return if Milvus has the collection
def has_collection(self, collection_name):
try:
return utility.has_collection(collection_name)
except Exception as e:
LOGGER.error("Failed to load data to Milvus: {}".format(e))
LOGGER.error("Failed: {}".format(e))
sys.exit(1)

# Create milvus collection if not exists
Expand All @@ -46,6 +44,8 @@ def create_collection(self, collection_name):
schema = CollectionSchema(fields=[field1, field2], description="collection description")
self.collection = Collection(name=collection_name, schema=schema)
LOGGER.debug("Create Milvus collection: {}".format(self.collection))
else:
self.collection = Collection(name=collection_name)
return "OK"
except Exception as e:
LOGGER.error("Failed to load data to Milvus: {}".format(e))
Expand All @@ -55,7 +55,7 @@ def create_collection(self, collection_name):
def insert(self, collection_name, vectors):
try:
self.create_collection(collection_name)
self.collection = Collection(name=collection_name)
# self.collection = Collection(name=collection_name)
data = [vectors]
mr = self.collection.insert(data)
ids = mr.primary_keys
Expand Down
2 changes: 1 addition & 1 deletion solutions/question_answering_system/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PyMySQL
numpy
pymilvus-orm==2.0.0rc1
pymilvus==2.0.0rc5
pandas
sentence_transformers==1.2.0

0 comments on commit fd0e029

Please sign in to comment.