feat: load_nltk

This commit is contained in:
martsforever
2025-09-07 20:16:30 +08:00
parent 6940d24d53
commit 185c16b06b
2 changed files with 20 additions and 0 deletions
+6
View File
@@ -7,6 +7,7 @@ from llama_index.vector_stores.milvus import MilvusVectorStore
from app.config.env import env
from app.utils.llm_utils import create_embeddings, create_llama_index_llm
from app.utils.nltk_utils import load_nltk
class MilvusService:
@@ -49,6 +50,11 @@ class MilvusService:
vector_store=vector_store,
embed_model=self.embeddings,
)
# 预先加载NLTK语料库以避免多线程环境中的竞争条件
# 否则在多线程环境下,parser.get_nodes_from_documents 可能会出现报错信息:'WordListCorpusReader' object has no attribute '_LazyCorpusLoader__args'
load_nltk()
from llama_index.core.node_parser import SimpleNodeParser
# parser = HierarchicalNodeParser.from_defaults(chunk_sizes=[2048, 512, 128])
parser = SimpleNodeParser()