From c4b22134f831a51dc5e18cbb7777074520e30829 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Thu, 24 Mar 2022 17:15:17 +0800 Subject: [PATCH 1/2] Fix Chinese garbled code --- .../quick_deploy/server/src/milvus_helpers.py | 1 + .../quick_deploy/server/src/mysql_helpers.py | 1 + 2 files changed, 2 insertions(+) diff --git a/solutions/question_answering_system/quick_deploy/server/src/milvus_helpers.py b/solutions/question_answering_system/quick_deploy/server/src/milvus_helpers.py index a9385041b..2ce8ef815 100644 --- a/solutions/question_answering_system/quick_deploy/server/src/milvus_helpers.py +++ b/solutions/question_answering_system/quick_deploy/server/src/milvus_helpers.py @@ -56,6 +56,7 @@ def insert(self, collection_name, vectors): try: self.create_collection(collection_name) data = [vectors] + self.set_collection(collection_name) mr = self.collection.insert(data) ids = mr.primary_keys self.collection.load() diff --git a/solutions/question_answering_system/quick_deploy/server/src/mysql_helpers.py b/solutions/question_answering_system/quick_deploy/server/src/mysql_helpers.py index 6cbeede8f..3b4b24f8c 100644 --- a/solutions/question_answering_system/quick_deploy/server/src/mysql_helpers.py +++ b/solutions/question_answering_system/quick_deploy/server/src/mysql_helpers.py @@ -42,6 +42,7 @@ def load_data_to_mysql(self, table_name, data): # Batch insert (Milvus_ids, img_path) to mysql self.test_connection() sql = "insert into " + table_name + " (milvus_id,question,answer) values (%s,%s,%s);" + self.cursor.execute('SET character_set_connection=utf8;') try: self.cursor.executemany(sql, data) self.conn.commit() From 7f644f27c7ecd48ad2f7e5b819b22ebabe713285 Mon Sep 17 00:00:00 2001 From: gouzi <530971494@qq.com> Date: Fri, 25 Mar 2022 10:42:25 +0800 Subject: [PATCH 2/2] solve issue [#1042](https://github.com/milvus-io/bootcamp/issues/1042) --- .../quick_deploy/server/src/mysql_helpers.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/solutions/question_answering_system/quick_deploy/server/src/mysql_helpers.py b/solutions/question_answering_system/quick_deploy/server/src/mysql_helpers.py index 3b4b24f8c..78d96face 100644 --- a/solutions/question_answering_system/quick_deploy/server/src/mysql_helpers.py +++ b/solutions/question_answering_system/quick_deploy/server/src/mysql_helpers.py @@ -72,7 +72,10 @@ def search_by_question(self, question, table_name): self.cursor.execute(sql) results = self.cursor.fetchall() LOGGER.debug("MYSQL search by question.") - return results[0][0] + if results: + return results[0][0] + else: + return results except Exception as e: LOGGER.error(f"MYSQL ERROR: {e} with sql: {sql}".format(e, sql)) sys.exit(1)