Skip to content

Commit

Permalink
Remove caching for search indexer (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidMStraub authored Nov 25, 2024
1 parent daa5bf5 commit 5a1f43f
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions gramps_webapi/api/search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,10 @@
from .indexer import SearchIndexer, SemanticSearchIndexer, SearchIndexerBase
from .embeddings import embedding_function_factory

_KEY_INDEXER = "_SEARCH_INDEXER"
_KEY_INDEXER_SEMANTIC = "_SEARCH_INDEXER_SEMANTIC"


def get_search_indexer(tree: str, semantic: bool = False) -> SearchIndexerBase:
"""Get the search indexer for the tree."""
# return cached instances if possible
if not semantic and (indexer := current_app.config.get(_KEY_INDEXER)):
return indexer
if semantic and (indexer := current_app.config.get(_KEY_INDEXER_SEMANTIC)):
return indexer
db_url = current_app.config["SEARCH_INDEX_DB_URI"] or None
if not db_url and current_app.config["SEARCH_INDEX_DIR"]:
# backwards compatibility...
Expand All @@ -65,10 +58,7 @@ def get_search_indexer(tree: str, semantic: bool = False) -> SearchIndexerBase:
except OSError:
raise ValueError(f"Failed initializing model {model}")
# cache on app instance
current_app.config[_KEY_INDEXER_SEMANTIC] = SemanticSearchIndexer(
return SemanticSearchIndexer(
db_url=db_url, tree=tree, embedding_function=embedding_function
)
return current_app.config[_KEY_INDEXER_SEMANTIC]
# cache on app instance
current_app.config[_KEY_INDEXER] = SearchIndexer(db_url=db_url, tree=tree)
return current_app.config[_KEY_INDEXER]
return SearchIndexer(db_url=db_url, tree=tree)

0 comments on commit 5a1f43f

Please sign in to comment.