josephrocca / OpenCharacters

Simple little web interface for creating characters and chatting with them. It's basically a single HTML file - no server. Share characters using a link (character data is stored within the URL itself). All chat data is stored in your browser using IndexedDB. Currently supports OpenAI APIs and ~any Hugging Face model.
https://josephrocca.github.io/OpenCharacters
MIT License
364 stars 60 forks source link

memory structures - custom code #53

Closed Bobolx00 closed 1 year ago

Bobolx00 commented 1 year ago

i read that phrases in docs : Create your own memory structures (embedding, retrieval, etc.)

Improve your character's memory by setting up your own embedding/retrieval system

is this already implemented?

josephrocca commented 1 year ago

You can definitely do this with custom code: https://github.com/josephrocca/OpenCharacters/blob/main/docs/custom-code.md

You'll likely want to use this Transformers.js model for text embeddings: https://gist.github.com/josephrocca/f40f04f4dea46f69385012e548871a35

And for retrieval you can use this function to compare vectors:

export function cosineDistance(vector1, vector2) {
  let dotProduct = 0;
  let norm1 = 0;
  let norm2 = 0;
  for(let i=0; i<vector1.length; i++) {
    dotProduct += vector1[i] * vector2[i];
    norm1 += vector1[i] * vector1[i];
    norm2 += vector2[i] * vector2[i];
  }
  return 1 - (dotProduct / (Math.sqrt(norm1) * Math.sqrt(norm2)));
}

Feel free to ping me with any further questions (my replies may be a bit delayed though)