fix detached instance error in keyword index create thread and fix question classifier node out of index error (#3219)

This commit is contained in:
Jyong 2024-04-09 14:34:51 +08:00 committed by GitHub
parent 581836b716
commit 33ea689861
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 4 deletions

View File

@ -661,7 +661,7 @@ class IndexingRunner:
# create keyword index
create_keyword_thread = threading.Thread(target=self._process_keyword_index,
args=(current_app._get_current_object(),
dataset, dataset_document, documents))
dataset.id, dataset_document.id, documents))
create_keyword_thread.start()
if dataset.indexing_technique == 'high_quality':
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
@ -690,14 +690,17 @@ class IndexingRunner:
}
)
def _process_keyword_index(self, flask_app, dataset, dataset_document, documents):
def _process_keyword_index(self, flask_app, dataset_id, document_id, documents):
with flask_app.app_context():
dataset = Dataset.query.filter_by(id=dataset_id).first()
if not dataset:
raise ValueError("no dataset found")
keyword = Keyword(dataset)
keyword.create(documents)
if dataset.indexing_technique != 'high_quality':
document_ids = [document.metadata['doc_id'] for document in documents]
db.session.query(DocumentSegment).filter(
DocumentSegment.document_id == dataset_document.id,
DocumentSegment.document_id == document_id,
DocumentSegment.index_node_id.in_(document_ids),
DocumentSegment.status == "indexing"
).update({

View File

@ -65,7 +65,9 @@ class QuestionClassifierNode(LLMNode):
categories = [_class.name for _class in node_data.classes]
try:
result_text_json = json.loads(result_text.strip('```JSON\n'))
categories = result_text_json.get('categories', [])
categories_result = result_text_json.get('categories', [])
if categories_result:
categories = categories_result
except Exception:
logging.error(f"Failed to parse result text: {result_text}")
try: