mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-15 07:35:27 +03:00
Handle case where embeddings overflow token limit
This commit is contained in:
parent
0abd514064
commit
88f6c3d096
@ -7,6 +7,7 @@ import os
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from numpy import ndarray
|
from numpy import ndarray
|
||||||
|
import onnxruntime as ort
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from playhouse.shortcuts import model_to_dict
|
from playhouse.shortcuts import model_to_dict
|
||||||
|
|
||||||
@ -174,7 +175,16 @@ class Embeddings:
|
|||||||
return embedding
|
return embedding
|
||||||
|
|
||||||
def batch_upsert_description(self, event_descriptions: dict[str, str]) -> ndarray:
|
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())
|
ids = list(event_descriptions.keys())
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user