Fix linting
This commit is contained in:
parent
ba7b3cedb5
commit
8a293a2c07
1 changed files with 55 additions and 51 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
"""
|
"""
|
||||||
Diagnostic tool to check LightRAG initialization status.
|
Diagnostic tool to check LightRAG initialization status.
|
||||||
|
|
||||||
This tool helps developers verify that their LightRAG instance is properly
|
This tool helps developers verify that their LightRAG instance is properly
|
||||||
initialized before use, preventing common initialization errors.
|
initialized before use, preventing common initialization errors.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
@ -11,7 +11,6 @@ Usage:
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import sys
|
import sys
|
||||||
from typing import Optional
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# Add parent directory to path for imports
|
# Add parent directory to path for imports
|
||||||
|
|
@ -24,44 +23,46 @@ from lightrag.base import StoragesStatus
|
||||||
async def check_lightrag_setup(rag_instance: LightRAG, verbose: bool = False) -> bool:
|
async def check_lightrag_setup(rag_instance: LightRAG, verbose: bool = False) -> bool:
|
||||||
"""
|
"""
|
||||||
Check if a LightRAG instance is properly initialized.
|
Check if a LightRAG instance is properly initialized.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
rag_instance: The LightRAG instance to check
|
rag_instance: The LightRAG instance to check
|
||||||
verbose: If True, print detailed diagnostic information
|
verbose: If True, print detailed diagnostic information
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
True if properly initialized, False otherwise
|
True if properly initialized, False otherwise
|
||||||
"""
|
"""
|
||||||
issues = []
|
issues = []
|
||||||
warnings = []
|
warnings = []
|
||||||
|
|
||||||
print("🔍 Checking LightRAG initialization status...\n")
|
print("🔍 Checking LightRAG initialization status...\n")
|
||||||
|
|
||||||
# Check storage initialization status
|
# Check storage initialization status
|
||||||
if not hasattr(rag_instance, '_storages_status'):
|
if not hasattr(rag_instance, "_storages_status"):
|
||||||
issues.append("LightRAG instance missing _storages_status attribute")
|
issues.append("LightRAG instance missing _storages_status attribute")
|
||||||
elif rag_instance._storages_status != StoragesStatus.INITIALIZED:
|
elif rag_instance._storages_status != StoragesStatus.INITIALIZED:
|
||||||
issues.append(f"Storages not initialized (status: {rag_instance._storages_status.name})")
|
issues.append(
|
||||||
|
f"Storages not initialized (status: {rag_instance._storages_status.name})"
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
print("✅ Storage status: INITIALIZED")
|
print("✅ Storage status: INITIALIZED")
|
||||||
|
|
||||||
# Check individual storage components
|
# Check individual storage components
|
||||||
storage_components = [
|
storage_components = [
|
||||||
('full_docs', 'Document storage'),
|
("full_docs", "Document storage"),
|
||||||
('text_chunks', 'Text chunks storage'),
|
("text_chunks", "Text chunks storage"),
|
||||||
('entities_vdb', 'Entity vector database'),
|
("entities_vdb", "Entity vector database"),
|
||||||
('relationships_vdb', 'Relationship vector database'),
|
("relationships_vdb", "Relationship vector database"),
|
||||||
('chunks_vdb', 'Chunks vector database'),
|
("chunks_vdb", "Chunks vector database"),
|
||||||
('doc_status', 'Document status tracker'),
|
("doc_status", "Document status tracker"),
|
||||||
('llm_response_cache', 'LLM response cache'),
|
("llm_response_cache", "LLM response cache"),
|
||||||
('full_entities', 'Entity storage'),
|
("full_entities", "Entity storage"),
|
||||||
('full_relations', 'Relation storage'),
|
("full_relations", "Relation storage"),
|
||||||
('chunk_entity_relation_graph', 'Graph storage')
|
("chunk_entity_relation_graph", "Graph storage"),
|
||||||
]
|
]
|
||||||
|
|
||||||
if verbose:
|
if verbose:
|
||||||
print("\n📦 Storage Components:")
|
print("\n📦 Storage Components:")
|
||||||
|
|
||||||
for component, description in storage_components:
|
for component, description in storage_components:
|
||||||
if not hasattr(rag_instance, component):
|
if not hasattr(rag_instance, component):
|
||||||
issues.append(f"Missing storage component: {component} ({description})")
|
issues.append(f"Missing storage component: {component} ({description})")
|
||||||
|
|
@ -69,52 +70,57 @@ async def check_lightrag_setup(rag_instance: LightRAG, verbose: bool = False) ->
|
||||||
storage = getattr(rag_instance, component)
|
storage = getattr(rag_instance, component)
|
||||||
if storage is None:
|
if storage is None:
|
||||||
warnings.append(f"Storage {component} is None (might be optional)")
|
warnings.append(f"Storage {component} is None (might be optional)")
|
||||||
elif hasattr(storage, '_storage_lock'):
|
elif hasattr(storage, "_storage_lock"):
|
||||||
if storage._storage_lock is None:
|
if storage._storage_lock is None:
|
||||||
issues.append(f"Storage {component} not initialized (lock is None)")
|
issues.append(f"Storage {component} not initialized (lock is None)")
|
||||||
elif verbose:
|
elif verbose:
|
||||||
print(f" ✅ {description}: Ready")
|
print(f" ✅ {description}: Ready")
|
||||||
elif verbose:
|
elif verbose:
|
||||||
print(f" ✅ {description}: Ready")
|
print(f" ✅ {description}: Ready")
|
||||||
|
|
||||||
# Check pipeline status
|
# Check pipeline status
|
||||||
try:
|
try:
|
||||||
from lightrag.kg.shared_storage import get_namespace_data
|
from lightrag.kg.shared_storage import get_namespace_data
|
||||||
|
|
||||||
get_namespace_data("pipeline_status")
|
get_namespace_data("pipeline_status")
|
||||||
print("✅ Pipeline status: INITIALIZED")
|
print("✅ Pipeline status: INITIALIZED")
|
||||||
except KeyError:
|
except KeyError:
|
||||||
issues.append("Pipeline status not initialized - call initialize_pipeline_status()")
|
issues.append(
|
||||||
|
"Pipeline status not initialized - call initialize_pipeline_status()"
|
||||||
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
issues.append(f"Error checking pipeline status: {str(e)}")
|
issues.append(f"Error checking pipeline status: {str(e)}")
|
||||||
|
|
||||||
# Print results
|
# Print results
|
||||||
print("\n" + "=" * 50)
|
print("\n" + "=" * 50)
|
||||||
|
|
||||||
if issues:
|
if issues:
|
||||||
print("❌ Issues found:\n")
|
print("❌ Issues found:\n")
|
||||||
for issue in issues:
|
for issue in issues:
|
||||||
print(f" • {issue}")
|
print(f" • {issue}")
|
||||||
|
|
||||||
print("\n📝 To fix, run this initialization sequence:\n")
|
print("\n📝 To fix, run this initialization sequence:\n")
|
||||||
print(" await rag.initialize_storages()")
|
print(" await rag.initialize_storages()")
|
||||||
print(" from lightrag.kg.shared_storage import initialize_pipeline_status")
|
print(" from lightrag.kg.shared_storage import initialize_pipeline_status")
|
||||||
print(" await initialize_pipeline_status()")
|
print(" await initialize_pipeline_status()")
|
||||||
print("\n📚 Documentation: https://github.com/HKUDS/LightRAG#important-initialization-requirements")
|
print(
|
||||||
|
"\n📚 Documentation: https://github.com/HKUDS/LightRAG#important-initialization-requirements"
|
||||||
|
)
|
||||||
|
|
||||||
if warnings and verbose:
|
if warnings and verbose:
|
||||||
print("\n⚠️ Warnings (might be normal):")
|
print("\n⚠️ Warnings (might be normal):")
|
||||||
for warning in warnings:
|
for warning in warnings:
|
||||||
print(f" • {warning}")
|
print(f" • {warning}")
|
||||||
|
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
print("✅ LightRAG is properly initialized and ready to use!")
|
print("✅ LightRAG is properly initialized and ready to use!")
|
||||||
|
|
||||||
if warnings and verbose:
|
if warnings and verbose:
|
||||||
print("\n⚠️ Warnings (might be normal):")
|
print("\n⚠️ Warnings (might be normal):")
|
||||||
for warning in warnings:
|
for warning in warnings:
|
||||||
print(f" • {warning}")
|
print(f" • {warning}")
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -122,55 +128,53 @@ async def demo():
|
||||||
"""Demonstrate the diagnostic tool with a test instance."""
|
"""Demonstrate the diagnostic tool with a test instance."""
|
||||||
from lightrag.llm.openai import openai_embed, gpt_4o_mini_complete
|
from lightrag.llm.openai import openai_embed, gpt_4o_mini_complete
|
||||||
from lightrag.kg.shared_storage import initialize_pipeline_status
|
from lightrag.kg.shared_storage import initialize_pipeline_status
|
||||||
|
|
||||||
print("=" * 50)
|
print("=" * 50)
|
||||||
print("LightRAG Initialization Diagnostic Tool")
|
print("LightRAG Initialization Diagnostic Tool")
|
||||||
print("=" * 50)
|
print("=" * 50)
|
||||||
|
|
||||||
# Create test instance
|
# Create test instance
|
||||||
rag = LightRAG(
|
rag = LightRAG(
|
||||||
working_dir="./test_diagnostic",
|
working_dir="./test_diagnostic",
|
||||||
embedding_func=openai_embed,
|
embedding_func=openai_embed,
|
||||||
llm_model_func=gpt_4o_mini_complete,
|
llm_model_func=gpt_4o_mini_complete,
|
||||||
)
|
)
|
||||||
|
|
||||||
print("\n🔴 BEFORE initialization:\n")
|
print("\n🔴 BEFORE initialization:\n")
|
||||||
await check_lightrag_setup(rag, verbose=True)
|
await check_lightrag_setup(rag, verbose=True)
|
||||||
|
|
||||||
print("\n" + "=" * 50)
|
print("\n" + "=" * 50)
|
||||||
print("\n🔄 Initializing...\n")
|
print("\n🔄 Initializing...\n")
|
||||||
await rag.initialize_storages()
|
await rag.initialize_storages()
|
||||||
await initialize_pipeline_status()
|
await initialize_pipeline_status()
|
||||||
|
|
||||||
print("\n🟢 AFTER initialization:\n")
|
print("\n🟢 AFTER initialization:\n")
|
||||||
await check_lightrag_setup(rag, verbose=True)
|
await check_lightrag_setup(rag, verbose=True)
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
shutil.rmtree("./test_diagnostic", ignore_errors=True)
|
shutil.rmtree("./test_diagnostic", ignore_errors=True)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(description="Check LightRAG initialization status")
|
||||||
description="Check LightRAG initialization status"
|
parser.add_argument(
|
||||||
|
"--demo", action="store_true", help="Run a demonstration with a test instance"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--demo",
|
"--verbose",
|
||||||
|
"-v",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
help="Run a demonstration with a test instance"
|
help="Show detailed diagnostic information",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
|
||||||
"--verbose", "-v",
|
|
||||||
action="store_true",
|
|
||||||
help="Show detailed diagnostic information"
|
|
||||||
)
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if args.demo:
|
if args.demo:
|
||||||
asyncio.run(demo())
|
asyncio.run(demo())
|
||||||
else:
|
else:
|
||||||
print("Run with --demo to see the diagnostic tool in action")
|
print("Run with --demo to see the diagnostic tool in action")
|
||||||
print("Or import this module and use check_lightrag_setup() with your instance")
|
print("Or import this module and use check_lightrag_setup() with your instance")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue