cheshire-cat-ai / core

Production ready AI agent framework
https://cheshirecat.ai
GNU General Public License v3.0
2.14k stars 282 forks source link

[Refactor] Abstract Vector Memory and simple api from plugins #818

Open valentimarco opened 1 month ago

valentimarco commented 1 month ago
  1. Abstract API for the Vectory Memory (so in future we are able to attach different dbs)
  2. Refactor the embedding stuff (@pieroit i don't remember why we need it, wasn't for the tool's examples?)
  3. Add api for doing stuff in plugins, for example 'cat.declerative_memory.filter({})'
pieroit commented 1 month ago
  1. Abstract API for the Vectory Memory (so in future we are able to attach different dbs)

Not strictly necessary to be honest, we fly well with Qdrant. Abstracting is a good idea to encapsulate it and avoid breaking changes coming from them

  1. Refactor the embedding stuff (@pieroit i don't remember why we need it, wasn't for the tool's examples?)

VectorMemoryCollection class has become spaghetti code, it is not on par with other ones

  1. Add api for doing stuff in plugins, for example 'cat.declerative_memory.filter({})'

Nice!

valentimarco commented 4 weeks ago

(03/06 dev meating) in the straycat:

def recall(query: str | Embedding, metadata: dict  = none, search_declerative: bool = true, search_procedural: bool = true, search_episodic: bool = true, override_working_memory: bool = true): Set[Document]

Method to search in memory and must have:

nicola-corbellini commented 4 weeks ago

Maybe it can be useful to return also the scores and the embeddings of the recalled points. E.g., at first, it could return Set[Tuple[str, float, List[float]]] like there is in other parts of the framework. Probably I'm saying something trivial, but, later on, we could start designing a custom Memory class like

class Memory
    text: str
    embedding: List[float]
    metadata: dict
    score: float (?)
    def to_document(self): -> Document

also, other params for the recall method may be: min_score: float to recall memories with a minimum score, k: int for the max number of memories returned and if k=-1|None the method could just use scroll from qdrant and return all the points.

valentimarco commented 4 weeks ago

I like the Memory class but should be uniform in all framework

pieroit commented 4 weeks ago

Awesome, agree with @nicola-corbellini on having a custom class to throw memories/points/documents around. Step 1: Follow the same output as StrayCat.recall_memories_to_working_memory Step 2: standardize with internal class

About the method, to reelaborate on @valentimarco 's proposal

def recall(
  self,
  query: str | Embedding,
  metadata: dict  = None,
  collection: str | None = None, # searches all by default
  override_working_memory: bool = False
) -> List[Tuple[float, Document]]:
nickprock commented 1 week ago

Hi guys, can I help you on this task?

pieroit commented 1 day ago

Hi guys, can I help you on this task?

Hi @nickprock thanks There is already a PR #848 on the recall function, what of the other topics would you like to tackle?

nickprock commented 1 day ago

Thanks @pieroit but I think I was too far behind on the project, I couldn't get anything right

pieroit commented 1 day ago

Thanks @pieroit but I think I was too far behind on the project, I couldn't get anything right

Available anytime for a code tour!