[ADD]Add functions related to knowledge base graph:

Add functions related to knowledge base graph:
1. Entity type generation,
2. Knowledge base graph acquisition,
3. Hard deletion of knowledge base graph,
4. Knowledge base graph reconstruction (asynchronous)
This commit is contained in:
lixiangcheng1
2025-12-27 13:53:10 +08:00
parent 06f64809c3
commit a0c362244e
35 changed files with 6267 additions and 143 deletions

View File

@@ -0,0 +1,13 @@
import os
def singleton(cls, *args, **kw):
instances = {}
def _singleton():
key = str(cls) + str(os.getpid())
if key not in instances:
instances[key] = cls(*args, **kw)
return instances[key]
return _singleton

View File

@@ -0,0 +1,4 @@
class TaskCanceledException(Exception):
def __init__(self, msg):
self.msg = msg

View File

@@ -0,0 +1,13 @@
import os
import logging
def log_exception(e, *args):
logging.exception(e)
for a in args:
if hasattr(a, "text"):
logging.error(a.text)
raise Exception(a.text)
else:
logging.error(str(a))
raise e

View File

@@ -1,2 +1,24 @@
from app.core.rag.utils import es_conn
from app.core.rag.nlp import search
from app.core.rag.graphrag import search as kg_search
PARALLEL_DEVICES: int = 0
docStoreConn = None
retriever = None
kg_retriever = None
def init_settings():
global docStoreConn, retriever, kg_retriever
if docStoreConn is None:
docStoreConn = es_conn.ESConnection()
if retriever is None:
retriever = search.Dealer(docStoreConn)
if kg_retriever is None:
kg_retriever = kg_search.KGSearch(docStoreConn)
init_settings()