Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lowering recall threshold #912

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions core/cat/looking_glass/recall_settings.py
Original file line number Diff line number Diff line change
@@ -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)
29 changes: 8 additions & 21 deletions core/cat/looking_glass/stray_cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down