From b25f221b10e8cd2b989141433e5c991c065e43e1 Mon Sep 17 00:00:00 2001 From: scicco Date: Mon, 16 Sep 2024 19:37:50 +0200 Subject: [PATCH] lowering recall threshold; create separate RecallSettings class --- core/cat/looking_glass/recall_settings.py | 31 +++++++++++++++++++++++ core/cat/looking_glass/stray_cat.py | 29 ++++++--------------- 2 files changed, 39 insertions(+), 21 deletions(-) create mode 100644 core/cat/looking_glass/recall_settings.py diff --git a/core/cat/looking_glass/recall_settings.py b/core/cat/looking_glass/recall_settings.py new file mode 100644 index 00000000..1bf4442f --- /dev/null +++ b/core/cat/looking_glass/recall_settings.py @@ -0,0 +1,31 @@ +"""Module for retrieving default configurations for episodic, declarative and procedural memories""" + + +class RecallSettings: + """Class for retrieving default configurations for episodic, declarative and procedural memories""" + + DEFAULT_K = 3 + DEFAULT_TRESHOLD = 0.5 + + def _build_settings( + self, + recall_query_embedding, + user_id=None, + k=DEFAULT_K, + treshold=DEFAULT_TRESHOLD, + ): + return { + "embedding": recall_query_embedding, + "k": k, + "threshold": treshold, + "metadata": {"source": user_id} if user_id else None, + } + + def default_episodic_config(self, recall_query_embedding, user_id): + return self._build_settings(recall_query_embedding, user_id) + + def default_declarative_config(self, recall_query_embedding): + return self._build_settings(recall_query_embedding) + + def default_procedural_config(self, recall_query_embedding): + return self._build_settings(recall_query_embedding) diff --git a/core/cat/looking_glass/stray_cat.py b/core/cat/looking_glass/stray_cat.py index bd9802a2..b93754e4 100644 --- a/core/cat/looking_glass/stray_cat.py +++ b/core/cat/looking_glass/stray_cat.py @@ -15,6 +15,7 @@ from cat.log import log from cat.looking_glass.cheshire_cat import CheshireCat from cat.looking_glass.callbacks import NewTokenHandler, ModelInteractionHandler +from cat.looking_glass.recall_settings import RecallSettings from cat.memory.working_memory import WorkingMemory from cat.convo.messages import CatMessage, UserMessage, MessageWhy, Role, EmbedderModelInteraction from cat.agents import AgentOutput @@ -232,27 +233,13 @@ def recall_relevant_memories_to_working_memory(self, query=None): self.mad_hatter.execute_hook("before_cat_recalls_memories", cat=self) # Setting default recall configs for each memory - # TODO: can these data structures become instances of a RecallSettings class? - default_episodic_recall_config = { - "embedding": recall_query_embedding, - "k": 3, - "threshold": 0.7, - "metadata": {"source": self.user_id}, - } - - default_declarative_recall_config = { - "embedding": recall_query_embedding, - "k": 3, - "threshold": 0.7, - "metadata": None, - } - - default_procedural_recall_config = { - "embedding": recall_query_embedding, - "k": 3, - "threshold": 0.7, - "metadata": None, - } + recall_settings = RecallSettings() + + default_episodic_recall_config = recall_settings.default_episodic_config(recall_query_embedding=recall_query_embedding, user_id=self.user_id) + + default_declarative_recall_config = recall_settings.default_declarative_config(recall_query_embedding=recall_query_embedding) + + default_procedural_recall_config = recall_settings.default_procedural_config(recall_query_embedding=recall_query_embedding) # hooks to change recall configs for each memory recall_configs = [