Skip to content

Commit

Permalink
RecallSettings now extends cat.utils.BaseModelDict
Browse files Browse the repository at this point in the history
  • Loading branch information
scicco committed Nov 3, 2024
1 parent b25f221 commit 2006338
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 34 deletions.
55 changes: 27 additions & 28 deletions core/cat/looking_glass/recall_settings.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
"""Module for retrieving default configurations for episodic, declarative and procedural memories"""

from typing import Any
from cat.utils import BaseModelDict

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)

class RecallSettingsMetadata(BaseModelDict):
"""Settigs's metadata for default configurations
Variables:
source (str): the source of the recall query
"""

source: str


class RecallSettings(BaseModelDict):
"""Class for retrieving default configurations for episodic, declarative and procedural memories
Variables:
embedding (Any): the embedding of the recall query - default None
k (int): the number of memories to return - default 3
threshold (float): the threshold - default 0.5
metadata (RecallSettingsMetadata): metadata - default None
"""

embedding: Any
k: int = 3
threshold: float = 0.5
metadata: RecallSettingsMetadata = None
17 changes: 11 additions & 6 deletions core/cat/looking_glass/stray_cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +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.looking_glass.recall_settings import RecallSettingsMetadata, RecallSettings
from cat.memory.working_memory import WorkingMemory
from cat.convo.messages import CatMessage, UserMessage, MessageWhy, Role, EmbedderModelInteraction
from cat.agents import AgentOutput
Expand Down Expand Up @@ -233,13 +233,18 @@ 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
recall_settings = RecallSettings()

default_episodic_recall_config = recall_settings.default_episodic_config(recall_query_embedding=recall_query_embedding, user_id=self.user_id)
default_episodic_recall_config = RecallSettings(
embedding=recall_query_embedding,
metadata=RecallSettingsMetadata(source=self.user_id),
)

default_declarative_recall_config = recall_settings.default_declarative_config(recall_query_embedding=recall_query_embedding)
default_declarative_recall_config = RecallSettings(
embedding=recall_query_embedding
)

default_procedural_recall_config = recall_settings.default_procedural_config(recall_query_embedding=recall_query_embedding)
default_procedural_recall_config = RecallSettings(
embedding=recall_query_embedding
)

# hooks to change recall configs for each memory
recall_configs = [
Expand Down

0 comments on commit 2006338

Please sign in to comment.