From ab0d3a08e2273b80fb03e89ca55bd342b9884a61 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Fri, 24 Feb 2023 00:27:29 -0600 Subject: [PATCH] Index configured plugins on app start and via update API endpoint --- src/khoj/configure.py | 13 +++++++++++++ src/khoj/utils/config.py | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/khoj/configure.py b/src/khoj/configure.py index 5755b9c2..33fb8250 100644 --- a/src/khoj/configure.py +++ b/src/khoj/configure.py @@ -8,6 +8,7 @@ import schedule # Internal Packages from khoj.processor.ledger.beancount_to_jsonl import BeancountToJsonl +from khoj.processor.jsonl.jsonl_to_jsonl import JsonlToJsonl from khoj.processor.markdown.markdown_to_jsonl import MarkdownToJsonl from khoj.processor.org_mode.org_to_jsonl import OrgToJsonl from khoj.search_type import image_search, text_search @@ -105,6 +106,18 @@ def configure_search(model: SearchModels, config: FullConfig, regenerate: bool, config.content_type.image, search_config=config.search_type.image, regenerate=regenerate ) + # Initialize External Plugin Search + if (t == None or t in state.SearchType) and config.content_type.plugins: + model.plugin_search = {} + for plugin_type, plugin_config in config.content_type.plugins.items(): + model.plugin_search[plugin_type] = text_search.setup( + JsonlToJsonl, + plugin_config, + search_config=config.search_type.asymmetric, + regenerate=regenerate, + filters=[DateFilter(), WordFilter(), FileFilter()], + ) + # Invalidate Query Cache state.query_cache = LRU() diff --git a/src/khoj/utils/config.py b/src/khoj/utils/config.py index 1e23e077..90691592 100644 --- a/src/khoj/utils/config.py +++ b/src/khoj/utils/config.py @@ -3,7 +3,7 @@ from __future__ import annotations # to avoid quoting type hints from enum import Enum from dataclasses import dataclass from pathlib import Path -from typing import TYPE_CHECKING, List +from typing import TYPE_CHECKING, Dict, List # External Packages import torch @@ -62,6 +62,7 @@ class SearchModels: music_search: TextSearchModel = None markdown_search: TextSearchModel = None image_search: ImageSearchModel = None + plugin_search: Dict[str, TextSearchModel] = None class ConversationProcessorConfigModel: