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 2 commits 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
30 changes: 30 additions & 0 deletions core/cat/looking_glass/recall_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Module for retrieving default configurations for episodic, declarative and procedural memories"""

from typing import Any
from cat.utils import BaseModelDict


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
34 changes: 13 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 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 @@ -232,27 +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
# 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,
}
default_episodic_recall_config = RecallSettings(
embedding=recall_query_embedding,
metadata=RecallSettingsMetadata(source=self.user_id),
)

default_declarative_recall_config = RecallSettings(
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