in agora/cerebral_api/src/tools/tools.py [0:0]
def main():
"""Command line interface for index tools."""
parser = argparse.ArgumentParser(description='ChromaDB Index Management Tools')
parser.add_argument('--clear', action='store_true', help='Clear the existing index')
parser.add_argument('--delete-collection', action='store_true', help='Delete and recreate the collection')
parser.add_argument('--reindex', action='store_true', help='Reindex all documents')
parser.add_argument('--stats', action='store_true', help='Show index statistics')
parser.add_argument('--documents-path', help='Path to documents directory for reindexing')
# Add search arguments
parser.add_argument('--search', help='Search query for semantic search')
parser.add_argument('--document', help='Search for specific document by name')
parser.add_argument('--limit', type=int, default=5, help='Maximum number of results to return')
parser.add_argument('--show-scores', action='store_true', help='Show relevance scores in results')
parser.add_argument('--full-content', action='store_true', help='Show full content instead of preview')
args = parser.parse_args()
try:
tools = IndexTools()
if args.stats or (not args.clear and not args.delete_collection and not args.reindex):
# Always show stats unless specifically only clearing/reindexing
stats = tools.get_index_stats()
logger.info("Index Statistics:")
for key, value in stats.items():
logger.info(f"- {key}: {value}")
if args.clear:
logger.info("Clearing index...")
success = tools.clear_index()
logger.info("Index cleared successfully" if success else "Failed to clear index")
if args.delete_collection:
logger.info("Deleting and recreating collection...")
success = tools.delete_collection()
logger.info("Collection recreated successfully" if success else "Failed to recreate collection")
if args.reindex:
logger.info("Reindexing documents...")
success = tools.reindex_documents(args.documents_path)
logger.info("Reindexing completed successfully" if success else "Reindexing failed")
# Handle search operations
if args.search or args.document:
results = tools.search_content(
query=args.search,
document_name=args.document,
limit=args.limit,
show_scores=args.show_scores
)
tools.display_search_results(results, show_full_content=args.full_content)
return 0
except Exception as e:
logger.error(f"Error running tools: {str(e)}")
return 1
return 0