Skip to content

Commit

Permalink
🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Jul 20, 2024
1 parent 8fd9ce1 commit e1ca392
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
21 changes: 20 additions & 1 deletion ovos_plugin_manager/embeddings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ovos_plugin_manager.templates.embeddings import EmbeddingsDB, FaceEmbeddingsRecognizer, VoiceEmbeddingsRecognizer
from ovos_plugin_manager.templates.embeddings import EmbeddingsDB, TextEmbeddingRecognizer, FaceEmbeddingsRecognizer, VoiceEmbeddingsRecognizer
from ovos_plugin_manager.utils import PluginTypes


Expand Down Expand Up @@ -57,3 +57,22 @@ def load_face_embeddings_plugin(module_name: str) -> type(FaceEmbeddingsRecogniz
"""
from ovos_plugin_manager.utils import load_plugin
return load_plugin(module_name, PluginTypes.FACE_EMBEDDINGS)


def find_text_embeddings_plugins() -> dict:
"""
Find all installed plugins
@return: dict plugin names to entrypoints
"""
from ovos_plugin_manager.utils import find_plugins
return find_plugins(PluginTypes.TEXT_EMBEDDINGS)


def load_text_embeddings_plugin(module_name: str) -> type(TextEmbeddingRecognizer):
"""
Get an uninstantiated class for the requested module_name
@param module_name: Plugin entrypoint name to load
@return: Uninstantiated class
"""
from ovos_plugin_manager.utils import load_plugin
return load_plugin(module_name, PluginTypes.TEXT_EMBEDDINGS)
21 changes: 21 additions & 0 deletions ovos_plugin_manager/templates/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@ def distance(self, embeddings_a: np.ndarray,
raise ValueError("Unsupported metric")


class TextEmbeddingRecognizer(EmbeddingsDB):
def __init__(self, db: EmbeddingsDB):
self.db = db

@abc.abstractmethod
def get_text_embeddings(self, text: str) -> np.ndarray:
return NotImplemented

def add_document(self, document: str) -> None:
embeddings = self.get_text_embeddings(document)
self.db.add_embeddings(document, embeddings)

def delete_document(self, document: str) -> None:
embeddings = self.get_text_embeddings(document)
self.db.delete_embedding(embeddings)

def query_document(self, document, top_k: int = 5) -> List[Tuple[str, float]]:
embeddings = self.get_text_embeddings(document)
return self.db.query(embeddings, top_k)


class FaceEmbeddingsRecognizer:
def __init__(self, db: EmbeddingsDB, thresh: float = 0.15):
self.db = db
Expand Down
2 changes: 2 additions & 0 deletions ovos_plugin_manager/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PluginTypes(str, Enum):
EMBEDDINGS = "opm.embeddings"
FACE_EMBEDDINGS = "opm.embeddings.face"
VOICE_EMBEDDINGS = "opm.embeddings.voice"
TEXT_EMBEDDINGS = "opm.embeddings.text"
GUI = "ovos.plugin.gui"
PHAL = "ovos.plugin.phal"
ADMIN = "ovos.plugin.phal.admin"
Expand Down Expand Up @@ -65,6 +66,7 @@ class PluginConfigTypes(str, Enum):
EMBEDDINGS = "opm.embeddings.config"
FACE_EMBEDDINGS = "opm.embeddings.face.config"
VOICE_EMBEDDINGS = "opm.embeddings.voice.config"
TEXT_EMBEDDINGS = "opm.embeddings.text.config"
GUI = "ovos.plugin.gui.config"
PHAL = "ovos.plugin.phal.config"
ADMIN = "ovos.plugin.phal.admin.config"
Expand Down

0 comments on commit e1ca392

Please sign in to comment.