From 41812c7d229a72b729d4bfe7956af04d33c3f7f0 Mon Sep 17 00:00:00 2001 From: Andy Lee Date: Mon, 28 Jul 2025 00:36:57 -0700 Subject: [PATCH] feat: add --use-existing-index option to google_history_reader_leann.py - Allow using existing index without rebuilding - Useful for testing pre-built indices --- examples/google_history_reader_leann.py | 47 ++++++++++++++++--------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/examples/google_history_reader_leann.py b/examples/google_history_reader_leann.py index 570cb5e..62781a4 100644 --- a/examples/google_history_reader_leann.py +++ b/examples/google_history_reader_leann.py @@ -298,6 +298,11 @@ async def main(): choices=["sentence-transformers", "openai", "mlx"], help="The embedding backend mode", ) + parser.add_argument( + "--use-existing-index", + action="store_true", + help="Use existing index without rebuilding", + ) args = parser.parse_args() @@ -308,26 +313,34 @@ async def main(): print(f"Index directory: {INDEX_DIR}") print(f"Max entries: {args.max_entries}") - # Find Chrome profile directories - from history_data.history import ChromeHistoryReader - - if args.auto_find_profiles: - profile_dirs = ChromeHistoryReader.find_chrome_profiles() - if not profile_dirs: - print("No Chrome profiles found automatically. Exiting.") + if args.use_existing_index: + # Use existing index without rebuilding + if not Path(INDEX_PATH).exists(): + print(f"Error: Index file not found at {INDEX_PATH}") return + print(f"Using existing index at {INDEX_PATH}") + index_path = INDEX_PATH else: - # Use single specified profile - profile_path = Path(args.chrome_profile) - if not profile_path.exists(): - print(f"Chrome profile not found: {profile_path}") - return - profile_dirs = [profile_path] + # Find Chrome profile directories + from history_data.history import ChromeHistoryReader - # Create or load the LEANN index from all sources - index_path = create_leann_index_from_multiple_chrome_profiles( - profile_dirs, INDEX_PATH, args.max_entries, args.embedding_model, args.embedding_mode - ) + if args.auto_find_profiles: + profile_dirs = ChromeHistoryReader.find_chrome_profiles() + if not profile_dirs: + print("No Chrome profiles found automatically. Exiting.") + return + else: + # Use single specified profile + profile_path = Path(args.chrome_profile) + if not profile_path.exists(): + print(f"Chrome profile not found: {profile_path}") + return + profile_dirs = [profile_path] + + # Create or load the LEANN index from all sources + index_path = create_leann_index_from_multiple_chrome_profiles( + profile_dirs, INDEX_PATH, args.max_entries, args.embedding_model, args.embedding_mode + ) if index_path: if args.query: