[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:
13
api/app/core/rag/common/decorator.py
Normal file
13
api/app/core/rag/common/decorator.py
Normal 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
|
||||
4
api/app/core/rag/common/exceptions.py
Normal file
4
api/app/core/rag/common/exceptions.py
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
class TaskCanceledException(Exception):
|
||||
def __init__(self, msg):
|
||||
self.msg = msg
|
||||
13
api/app/core/rag/common/log_utils.py
Normal file
13
api/app/core/rag/common/log_utils.py
Normal 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
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user