diff --git a/docs/docs/configuration/reference.md b/docs/docs/configuration/reference.md index e30ee1619..719a1efc7 100644 --- a/docs/docs/configuration/reference.md +++ b/docs/docs/configuration/reference.md @@ -535,7 +535,8 @@ semantic_search: # Optional: Enable semantic search (default: shown below) enabled: False # Optional: Re-index embeddings database from historical tracked objects (default: shown below) - reindex: False + # Resets on successful completion + reindex_next_startup: False # Optional: Set the model used for embeddings. (default: shown below) model: "jinav1" # Optional: Set the model size used for embeddings. (default: shown below) diff --git a/docs/docs/configuration/semantic_search.md b/docs/docs/configuration/semantic_search.md index 07e2cbfb2..ffca51fa7 100644 --- a/docs/docs/configuration/semantic_search.md +++ b/docs/docs/configuration/semantic_search.md @@ -24,14 +24,14 @@ Semantic Search is disabled by default, and must be enabled in your config file ```yaml semantic_search: enabled: True - reindex: False + reindex_next_startup: False ``` :::tip -The embeddings database can be re-indexed from the existing tracked objects in your database by adding `reindex: True` to your `semantic_search` configuration or by toggling the switch on the Search Settings page in the UI and restarting Frigate. Depending on the number of tracked objects you have, it can take a long while to complete and may max out your CPU while indexing. Make sure to turn the UI's switch off or set the config back to `False` before restarting Frigate again. +The embeddings database can be re-indexed from the existing tracked objects in your database by adding `reindex_next_startup: True` to your `semantic_search` configuration or by toggling the switch on the Search Settings page in the UI and restarting Frigate. Depending on the number of tracked objects you have, it can take a long while to complete and may max out your CPU while indexing. Once completed, this will automatically be set back to `False`. -If you are enabling Semantic Search for the first time, be advised that Frigate does not automatically index older tracked objects. You will need to enable the `reindex` feature in order to do that. +If you are enabling Semantic Search for the first time, be advised that Frigate does not automatically index older tracked objects. You will need to enable the `reindex_next_startup` feature in order to do that. ::: diff --git a/frigate/config/classification.py b/frigate/config/classification.py index aecbf6537..39b8007af 100644 --- a/frigate/config/classification.py +++ b/frigate/config/classification.py @@ -37,8 +37,9 @@ class ClassificationConfig(FrigateBaseModel): class SemanticSearchConfig(FrigateBaseModel): enabled: bool = Field(default=False, title="Enable semantic search.") - reindex: Optional[bool] = Field( - default=False, title="Reindex all tracked objects on startup." + reindex_next_startup: Optional[bool] = Field( + default=False, + title="Reindex all tracked objects on next startup. Resets to false on completion.", ) model: Optional[SemanticSearchModelEnum] = Field( default=SemanticSearchModelEnum.jinav1, diff --git a/frigate/embeddings/embeddings.py b/frigate/embeddings/embeddings.py index 7e866d1fe..0514daca4 100644 --- a/frigate/embeddings/embeddings.py +++ b/frigate/embeddings/embeddings.py @@ -20,7 +20,8 @@ from frigate.data_processing.types import DataProcessorMetrics from frigate.db.sqlitevecq import SqliteVecQueueDatabase from frigate.models import Event from frigate.types import ModelStatusTypesEnum -from frigate.util.builtin import serialize +from frigate.util.builtin import serialize, update_yaml_file +from frigate.util.config import find_config_file from frigate.util.path import get_event_thumbnail_bytes from .onnx.jina_v1_embedding import JinaV1ImageEmbedding, JinaV1TextEmbedding @@ -367,4 +368,12 @@ class Embeddings: ) totals["status"] = "completed" + self.config.semantic_search.reindex_next_startup = False + + update_yaml_file( + find_config_file(), + ["semantic_search", "reindex_next_startup"], + False, + ) + self.requestor.send_data(UPDATE_EMBEDDINGS_REINDEX_PROGRESS, totals) diff --git a/frigate/embeddings/maintainer.py b/frigate/embeddings/maintainer.py index 9b90f6f2c..b1c9ba352 100644 --- a/frigate/embeddings/maintainer.py +++ b/frigate/embeddings/maintainer.py @@ -85,7 +85,7 @@ class EmbeddingMaintainer(threading.Thread): self.embeddings = Embeddings(config, db, metrics) # Check if we need to re-index events - if config.semantic_search.reindex: + if config.semantic_search.reindex_next_startup: self.embeddings.reindex() # create communication for updating event descriptions diff --git a/web/public/locales/en/views/settings.json b/web/public/locales/en/views/settings.json index 4a7693416..b15335c61 100644 --- a/web/public/locales/en/views/settings.json +++ b/web/public/locales/en/views/settings.json @@ -89,7 +89,7 @@ "readTheDocumentation": "Read the Documentation", "reindexOnStartup": { "label": "Re-Index On Startup", - "desc": "Re-indexing will reprocess all thumbnails and descriptions (if enabled) and apply the embeddings on each startup. Don't forget to disable the option after restarting!" + "desc": "Re-indexing will reprocess all thumbnails and descriptions (if enabled) and apply the embeddings at next startup. This field will be reset after successfully completing." }, "modelSize": { "label": "Model Size", diff --git a/web/src/types/frigateConfig.ts b/web/src/types/frigateConfig.ts index d66d5edcb..c65f8c518 100644 --- a/web/src/types/frigateConfig.ts +++ b/web/src/types/frigateConfig.ts @@ -486,7 +486,7 @@ export interface FrigateConfig { semantic_search: { enabled: boolean; - reindex: boolean; + reindex_next_startup: boolean; model: SearchModel; model_size: SearchModelSize; }; diff --git a/web/src/views/settings/ClassificationSettingsView.tsx b/web/src/views/settings/ClassificationSettingsView.tsx index 24c3a9107..654d41c0e 100644 --- a/web/src/views/settings/ClassificationSettingsView.tsx +++ b/web/src/views/settings/ClassificationSettingsView.tsx @@ -25,7 +25,7 @@ import { Trans, useTranslation } from "react-i18next"; type ClassificationSettings = { search: { enabled?: boolean; - reindex?: boolean; + reindex_next_startup?: boolean; model_size?: SearchModelSize; }; face: { @@ -55,7 +55,7 @@ export default function ClassificationSettingsView({ useState({ search: { enabled: undefined, - reindex: undefined, + reindex_next_startup: undefined, model_size: undefined, }, face: { @@ -71,7 +71,7 @@ export default function ClassificationSettingsView({ useState({ search: { enabled: undefined, - reindex: undefined, + reindex_next_startup: undefined, model_size: undefined, }, face: { @@ -89,7 +89,7 @@ export default function ClassificationSettingsView({ setClassificationSettings({ search: { enabled: config.semantic_search.enabled, - reindex: config.semantic_search.reindex, + reindex_next_startup: config.semantic_search.reindex_next_startup, model_size: config.semantic_search.model_size, }, face: { @@ -105,7 +105,7 @@ export default function ClassificationSettingsView({ setOrigSearchSettings({ search: { enabled: config.semantic_search.enabled, - reindex: config.semantic_search.reindex, + reindex_next_startup: config.semantic_search.reindex_next_startup, model_size: config.semantic_search.model_size, }, face: { @@ -141,7 +141,7 @@ export default function ClassificationSettingsView({ axios .put( - `config/set?semantic_search.enabled=${classificationSettings.search.enabled ? "True" : "False"}&semantic_search.reindex=${classificationSettings.search.reindex ? "True" : "False"}&semantic_search.model_size=${classificationSettings.search.model_size}&face_recognition.enabled=${classificationSettings.face.enabled ? "True" : "False"}&face_recognition.model_size=${classificationSettings.face.model_size}&lpr.enabled=${classificationSettings.lpr.enabled ? "True" : "False"}`, + `config/set?semantic_search.enabled=${classificationSettings.search.enabled ? "True" : "False"}&semantic_search.reindex_next_startup=${classificationSettings.search.reindex_next_startup ? "True" : "False"}&semantic_search.model_size=${classificationSettings.search.model_size}&face_recognition.enabled=${classificationSettings.face.enabled ? "True" : "False"}&face_recognition.model_size=${classificationSettings.face.model_size}&lpr.enabled=${classificationSettings.lpr.enabled ? "True" : "False"}`, { requires_restart: 0, }, @@ -267,11 +267,11 @@ export default function ClassificationSettingsView({ { handleClassificationConfigChange({ - search: { reindex: isChecked }, + search: { reindex_next_startup: isChecked }, }); }} />