parent
852b0540c2
commit
0c7d934f31
@ -1 +1,3 @@
|
|||||||
https://dozerdb.org/
|
https://dozerdb.org/
|
||||||
|
|
||||||
|
https://milvus.io/
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,95 +0,0 @@
|
|||||||
import os
|
|
||||||
import asyncio
|
|
||||||
from lightrag import LightRAG, QueryParam
|
|
||||||
from lightrag.utils import EmbeddingFunc
|
|
||||||
from lightrag.kg.shared_storage import initialize_pipeline_status
|
|
||||||
|
|
||||||
from Config.Config import EMBED_DIM, EMBED_MAX_TOKEN_SIZE, NEO4J_URI, NEO4J_USERNAME, NEO4J_PASSWORD
|
|
||||||
from Util.LightRagUtil import llm_model_func, embedding_func
|
|
||||||
|
|
||||||
# WorkingDir
|
|
||||||
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
WORKING_DIR = os.path.join(ROOT_DIR, "myKG")
|
|
||||||
if not os.path.exists(WORKING_DIR):
|
|
||||||
os.mkdir(WORKING_DIR)
|
|
||||||
print(f"WorkingDir: {WORKING_DIR}")
|
|
||||||
|
|
||||||
# redis
|
|
||||||
os.environ["REDIS_URI"] = "redis://localhost:6379"
|
|
||||||
|
|
||||||
# neo4j
|
|
||||||
BATCH_SIZE_NODES = 500
|
|
||||||
BATCH_SIZE_EDGES = 100
|
|
||||||
os.environ["NEO4J_URI"] = NEO4J_URI
|
|
||||||
os.environ["NEO4J_USERNAME"] = NEO4J_USERNAME
|
|
||||||
os.environ["NEO4J_PASSWORD"] = NEO4J_PASSWORD
|
|
||||||
|
|
||||||
# milvus
|
|
||||||
os.environ["MILVUS_URI"] = "http://localhost:19530"
|
|
||||||
os.environ["MILVUS_USER"] = "root"
|
|
||||||
os.environ["MILVUS_PASSWORD"] = "Milvus"
|
|
||||||
os.environ["MILVUS_DB_NAME"] = "lightrag"
|
|
||||||
|
|
||||||
|
|
||||||
async def initialize_rag():
|
|
||||||
rag = LightRAG(
|
|
||||||
working_dir=WORKING_DIR,
|
|
||||||
llm_model_func=llm_model_func,
|
|
||||||
llm_model_max_token_size=32768,
|
|
||||||
embedding_func=EmbeddingFunc(
|
|
||||||
embedding_dim=EMBED_DIM,
|
|
||||||
max_token_size=EMBED_MAX_TOKEN_SIZE,
|
|
||||||
func=embedding_func
|
|
||||||
),
|
|
||||||
chunk_token_size=512,
|
|
||||||
chunk_overlap_token_size=256,
|
|
||||||
kv_storage="RedisKVStorage",
|
|
||||||
graph_storage="Neo4JStorage",
|
|
||||||
vector_storage="MilvusVectorDBStorage",
|
|
||||||
doc_status_storage="RedisKVStorage",
|
|
||||||
)
|
|
||||||
|
|
||||||
await rag.initialize_storages()
|
|
||||||
await initialize_pipeline_status()
|
|
||||||
|
|
||||||
return rag
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
# Initialize RAG instance
|
|
||||||
rag = asyncio.run(initialize_rag())
|
|
||||||
|
|
||||||
with open("./book.txt", "r", encoding="utf-8") as f:
|
|
||||||
rag.insert(f.read())
|
|
||||||
|
|
||||||
# Perform naive search
|
|
||||||
print(
|
|
||||||
rag.query(
|
|
||||||
"What are the top themes in this story?", param=QueryParam(mode="naive")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Perform local search
|
|
||||||
print(
|
|
||||||
rag.query(
|
|
||||||
"What are the top themes in this story?", param=QueryParam(mode="local")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Perform global search
|
|
||||||
print(
|
|
||||||
rag.query(
|
|
||||||
"What are the top themes in this story?", param=QueryParam(mode="global")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
# Perform hybrid search
|
|
||||||
print(
|
|
||||||
rag.query(
|
|
||||||
"What are the top themes in this story?", param=QueryParam(mode="hybrid")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
Loading…
Reference in new issue