From 0eccb6a610232394f60044d7dbe54c0c0b7df14f Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Tue, 15 Oct 2024 07:17:54 -0600 Subject: [PATCH] Db fixes (#14364) * Handle case where embeddings overflow token limit * Set notification tokens * Fix sort --- frigate/api/auth.py | 1 + frigate/embeddings/embeddings.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/frigate/api/auth.py b/frigate/api/auth.py index 5276eb71e..8976469f5 100644 --- a/frigate/api/auth.py +++ b/frigate/api/auth.py @@ -357,6 +357,7 @@ def create_user(request: Request, body: AppPostUsersBody): { User.username: body.username, User.password_hash: password_hash, + User.notification_tokens: [], } ).execute() return JSONResponse(content={"username": body.username}) diff --git a/frigate/embeddings/embeddings.py b/frigate/embeddings/embeddings.py index cb0626f7b..e4937f955 100644 --- a/frigate/embeddings/embeddings.py +++ b/frigate/embeddings/embeddings.py @@ -6,6 +6,7 @@ import logging import os import time +import onnxruntime as ort from numpy import ndarray from PIL import Image from playhouse.shortcuts import model_to_dict @@ -174,7 +175,16 @@ class Embeddings: return embedding def batch_upsert_description(self, event_descriptions: dict[str, str]) -> ndarray: - embeddings = self.text_embedding(list(event_descriptions.values())) + descs = list(event_descriptions.values()) + + try: + embeddings = self.text_embedding(descs) + except ort.RuntimeException: + half_size = len(descs) / 2 + embeddings = [] + embeddings.extend(self.text_embedding(descs[0:half_size])) + embeddings.extend(self.text_embedding(descs[half_size:])) + ids = list(event_descriptions.keys()) items = []