projectmemory

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2025 License: MIT Imports: 12 Imported by: 0

README

ProjectMemory

Go Reference Go Report Card

ProjectMemory is an MCP (Model Context Protocol) server that provides persistent storage for conversation context information using SQLite. This allows LLMs to remember and retrieve relevant information from past interactions.

Overview

ProjectMemory implements two MCP tools:

  1. save_context - Saves context (conversation snippets, inputs, outputs) to a persistent store
  2. retrieve_context - Retrieves relevant context based on semantic search

The service handles:

  • Summarizing text to extract key information
  • Creating embeddings for semantic search
  • Storing context with metadata in SQLite
  • Searching for relevant context using vector similarity

Components

  • Vector Package: Utilities for embedding operations and vector similarity
  • Summarizer Package: Text summarization capabilities
  • ContextStore Package: SQLite-based persistent storage
  • Server Package: MCP server implementation
  • Logger Package: Structured logging system

Getting Started

Prerequisites
  • Go 1.20+
  • SQLite
Configuration

Create a .projectmemoryconfig file in the project root:

{
  "models": {
    "provider": "mock",
    "modelId": "mock-model",
    "maxTokens": 1024,
    "temperature": 0.7
  },
  "database": {
    "path": ".projectmemory.db"
  },
  "logging": {
    "level": "INFO",
    "format": "TEXT"
  }
}
Running the Server

From the project root:

go run cmd/project-memory/main.go

Using as a Library

ProjectMemory can be used as a library in your Go applications in multiple ways:

  1. Direct Component Usage - Directly use the core components for maximum control
  2. Helper Functions - Use the CreateComponents helper for easier initialization
  3. High-Level API - Use the Server API for simplified operations

These approaches allow you to integrate ProjectMemory with your existing MCP server without conflicts. For detailed instructions and examples, see our Library Usage Guide and our comprehensive Embedding Guide.

Quick Example
import (
    "github.com/localrivet/projectmemory"
    "github.com/localrivet/projectmemory/internal/contextstore"
    "github.com/localrivet/projectmemory/internal/summarizer"
    "github.com/localrivet/projectmemory/internal/vector"
)

// Initialize components
store := contextstore.NewSQLiteContextStore()
store.Initialize(".projectmemory.db")
defer store.Close()

summ := summarizer.NewBasicSummarizer(summarizer.DefaultMaxSummaryLength)
summ.Initialize()

emb := vector.NewMockEmbedder(vector.DefaultEmbeddingDimensions)
emb.Initialize()

// Now you can use these components directly in your code
// For example, to store context:
testText := "This is a test context to save."
summary, _ := summ.Summarize(testText)
embedding, _ := emb.CreateEmbedding(summary)
embeddingBytes, _ := vector.Float32SliceToBytes(embedding)
id := projectmemory.GenerateHash(summary, time.Now().UnixNano())
store.Store(id, summary, embeddingBytes, time.Now())

For a complete example of integrating with an existing MCP server, see examples/embed-in-mcp/main.go.

API Reference

Tool: save_context

Request:

{
  "context_text": "The text to save in the context store"
}

Response:

{
  "status": "success",
  "id": "generated-unique-id"
}
Tool: retrieve_context

Request:

{
  "query": "The query to search for",
  "limit": 5
}

Response:

{
  "status": "success",
  "results": ["Matching context entry 1", "Matching context entry 2", "..."]
}
Tool: delete_context

Request:

{
  "id": "context-entry-id-to-delete"
}

Response:

{
  "status": "success"
}
Tool: clear_all_context

Request:

{
  "confirmation": "confirm"
}

Response:

{
  "status": "success"
}
Tool: replace_context

Request:

{
  "id": "context-entry-id-to-replace",
  "context_text": "The new text to replace the existing context"
}

Response:

{
  "status": "success"
}

Documentation

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateComponents

CreateComponents creates and initializes the core components without starting the server. This is useful when you want to use ProjectMemory components in your own MCP server.

func GenerateHash

func GenerateHash(content string, timestamp int64) string

GenerateHash creates a SHA-256 hash from content and a timestamp

Types

type Config

type Config struct {
	Models struct {
		Provider    string  `json:"provider"`
		ModelID     string  `json:"modelId"`
		MaxTokens   int     `json:"maxTokens"`
		Temperature float32 `json:"temperature"`
	} `json:"models"`
	Database struct {
		Path string `json:"path"`
	} `json:"database"`
	Logging struct {
		Level  string `json:"level"`
		Format string `json:"format"`
	} `json:"logging"`
}

Config represents the configuration structure for the ProjectMemory service.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a configuration with sensible defaults

func LoadConfig

func LoadConfig(filePath string) (*Config, error)

LoadConfig loads configuration from the specified file path

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents a ProjectMemory server instance

func NewServer

func NewServer(config *Config) (*Server, error)

NewServer creates a new ProjectMemory server with the provided configuration

func (*Server) ClearAllContext

func (s *Server) ClearAllContext() error

ClearAllContext removes all context entries from the store

func (*Server) DeleteContext

func (s *Server) DeleteContext(id string) error

DeleteContext deletes a specific context entry by ID

func (*Server) GetEmbedder

func (s *Server) GetEmbedder() vector.Embedder

GetEmbedder returns the server's embedder

func (*Server) GetLogger

func (s *Server) GetLogger() *logger.Logger

GetLogger returns the server's logger

func (*Server) GetStore

func (s *Server) GetStore() contextstore.ContextStore

GetStore returns the server's context store

func (*Server) GetSummarizer

func (s *Server) GetSummarizer() summarizer.Summarizer

GetSummarizer returns the server's summarizer

func (*Server) ReplaceContext

func (s *Server) ReplaceContext(id string, contextText string) (string, error)

ReplaceContext replaces an existing context with new content

func (*Server) RetrieveContext

func (s *Server) RetrieveContext(query string, limit int) ([]string, error)

RetrieveContext retrieves relevant context based on a query

func (*Server) SaveContext

func (s *Server) SaveContext(contextText string) (string, error)

SaveContext saves a context text to the memory store

func (*Server) Start

func (s *Server) Start() error

Start starts the ProjectMemory server

func (*Server) Stop

func (s *Server) Stop() error

Stop gracefully stops the ProjectMemory server

Directories

Path Synopsis
cmd
projectmemory command
examples
embed-in-mcp command
internal
contextstore
Package contextstore provides the storage components for the context data used by the ProjectMemory service.
Package contextstore provides the storage components for the context data used by the ProjectMemory service.
logger
Package logger provides a structured logging system for the projectmemory service.
Package logger provides a structured logging system for the projectmemory service.
server
Package server provides the MCP server implementation for the ProjectMemory service.
Package server provides the MCP server implementation for the ProjectMemory service.
summarizer
Package summarizer provides interfaces and implementations for summarizing text content within the ProjectMemory service.
Package summarizer provides interfaces and implementations for summarizing text content within the ProjectMemory service.
summarizer/providers
Package providers contains implementations of different LLM providers for text summarization.
Package providers contains implementations of different LLM providers for text summarization.
telemetry
Package telemetry provides metrics collection and reporting for monitoring the LLM-Memory service performance.
Package telemetry provides metrics collection and reporting for monitoring the LLM-Memory service performance.
tools
Package tools defines the interfaces and data structures for the ProjectMemory service.
Package tools defines the interfaces and data structures for the ProjectMemory service.
vector
Package vector provides vector embedding utilities and text embedding within the ProjectMemory service.
Package vector provides vector embedding utilities and text embedding within the ProjectMemory service.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL