npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@socialagi/memory

v0.0.4

Published

This library is a work in progress and currently only supports non-persistent in-memory storage.

Downloads

50

Readme

Open Souls Memory

This library is a work in progress and currently only supports non-persistent in-memory storage.

@socialagi/memory provides a simple way to store and retrieve memories using the MemoryStream class and the Embedder interface.

MemoryStream

The MemoryStream class is used to store and retrieve memories. Here's a basic example of how to use it:

import { MemoryStream } from "@socialagi/memory"

// Create a new instance of MemoryStream
const memoryStream = new MemoryStream()

// Store a memory
await memoryStream.store({
  id: "hi",
  content: "Hello, world!"
})

// Retrieve a memory
const memory = await memoryStream.get("hi")

// Search for memories with specific text
const returnedMemories = await memoryStream.search("hi said the canine")

Memories are saved using the Memory interface.

  • id: A unique identifier for the memory.
  • content: The content of the memory.
  • embedding: a vector returned from an embedding function
  • createdAt: The date and time when the memory was created.
  • updatedAt: The date and time when the memory was last updated.
  • metadata: A record of any additional data associated with the memory.
const memory: Memory = {
  id: "unique-id",
  content: "This is a memory.",
  embedding: [0.1, 0.2, 0.3, 0.4],
  createdAt: new Date(),
  updatedAt: new Date(),
  metadata: {
    author: "John Doe",
    location: "New York"
  }
}

Embeddings

Embeddings are a way to represent text data in a numerical format that can be processed by machine learning algorithms. In @socialagi/memory, we use the Embedder interface and its various implementations to create these embeddings.

Here's an example of how to use the default embedder:

import { getDefaultEmbedder } from "@socialagi/memory"

// Get the default embedder
const embedder = getDefaultEmbedder()

// Create an embedding
const embedding = await embedder.createEmbedding("Hello, world!")

The Embedder interface has a single method, createEmbedding(content: string), which takes a string and returns a Promise that resolves to an Embedding, which is an array of numbers.

We have two implementations of Embedder.

The defaultEmbeddder is a HuggingFaceEmbedder using the "Supabase/gte-small" model (which performs better )

  1. HuggingFaceEmbedder: This uses the Hugging Face Transformers library to create embeddings. It uses a model specified at instantiation (default is "Supabase/gte-small") and creates embeddings asynchronously.
import { HuggingFaceEmbedder } from "@socialagi/memory"

// Create a new instance of HuggingFaceEmbedder
const embedder = new HuggingFaceEmbedder()

// Create an embedding
const embedding = await embedder.createEmbedding("Hello, world!")
  1. nullEmbedder: This is a simple implementation that always returns an empty array. It's useful when you only want to store and retrieve recent memories, and don't need to search for memories.
import { nullEmbedder } from "@socialagi/memory"


const stream = new MemoryStream(nullEmbedder)