How pramodsultane/copilotmemory works
1. Repository purpose
- copilotmemory is a local-first Python package for storing and retrieving coding “memories” to improve Copilot context.
- The architecture centers on a memory pipeline: capture/store content, embed it, retrieve similar items, and expose results through CLI and HTTP API.
2. Top-level package boundary
- All runtime code lives under src/copilotmemory/, split into memory, api, cli, and utils.
- This is a clean separation of core domain logic from delivery channels: the same memory subsystem is reused by both the FastAPI layer and the Typer CLI.
3. Core memory subsystem
- src/copilotmemory/memory/ is the heart of the project.
- store.py likely owns persistence and CRUD for memory records.
- embedder.py transforms code/text into vector embeddings.
- retriever.py runs semantic lookup and relevance ranking over stored memories.
- For an architecture diagram, this subsystem should be shown as the central service layer that both interfaces depend on.
4. Data persistence model
- The README describes a dual-store design: vector storage for semantic search and SQLite for metadata.
- Environment variables such as MEMORY_DB_PATH and VECTOR_STORE_PATH imply local filesystem-backed persistence rather than remote services.
- The architecture boundary here is important: embeddings/search data are separated from operational metadata like timestamps, tags, and paths.
5. Embedding and retrieval flow
- New memories flow from raw code/snippets into normalization and embedding generation, then into the store.
- Query flow goes the other direction: natural-language search requests are embedded, compared against stored vectors, then filtered/ranked by threshold and limit.
- The retriever is the key coordination point for turning low-level similarity scores into user-facing context.
6. API delivery layer
- src/copilotmemory/api/routes.py exposes the HTTP surface, documented as FastAPI in the README.
- The API is thin: it validates requests, delegates to memory services, and formats responses for clients.
- Main endpoints are memory CRUD plus semantic search and health checking, making the API a façade over the memory subsystem.
7. CLI delivery layer
- src/copilotmemory/cli/commands.py provides local user operations with Typer.
- CLI commands mirror the API capabilities: store, search, prompt generation, list, show, delete, and serve.
- This suggests a single domain backend with two entry points: human-oriented local commands and programmatic HTTP access.
8. Configuration and cross-cutting utilities
- src/copilotmemory/utils/config.py centralizes environment-driven settings such as storage paths, host/port, embedding model, and retention policies.
- src/copilotmemory/utils/logger.py handles logging as a shared cross-cutting concern.
- These utilities are not core business logic, but they define operational behavior and deployment constraints.
9. Deployment and runtime shape
- The project is a Python 3.10+ package with local runtime dependencies on ChromaDB, sentence-transformers, FastAPI, and Typer.
- The README indicates a service mode (copilotmemory serve) and a containerized deployment path via Docker.
- In a diagram, the runtime boundary should show a single Python application with optional API server mode and local data directories.
10. Tests and quality gates
- tests/test_memory.py indicates direct testing of core memory behavior; the README also references API and CLI tests.
- Tooling in pyproject.toml is likely organized around pytest plus lint/type checks (ruff, black, mypy).
- The test boundary matters because the memory layer is the most critical and should be isolated from interface concerns.
11. Documentation and architecture intent
- docs/architecture.md likely expands the intended system design beyond what is implemented.
- The README’s architecture section describes the intended layering: capture, embedding, vector store, metadata, retrieval, and integrations.
- If you are drawing the diagram, use the README as the conceptual model, but anchor concrete components to the actual package layout in src/copilotmemory/.
12. Important implementation boundary to note
- The project is explicitly privacy-first and local-first: there is no required cloud dependency in the documented architecture.
- That means the main external dependencies are libraries, not hosted services; the primary “integration” boundaries are the API and CLI entry points rather than networked backends.
Main entry points: store.py store · routes.py API routes · commands.py CLI commands · __init__.py copilotmemory
Components 16
Runtime
Application entry points and delivery surfaces
- copilotmemory · Top-level package boundary for the local-first memory system
src/copilotmemory/__init__.py - API routes · HTTP surface for memory operations and health checks
src/copilotmemory/api/routes.py - CLI commands · Local command interface for storing, searching, and serving memories
src/copilotmemory/cli/commands.py
Core memory
Domain services for storing, embedding, and retrieving memories
- memory · Core memory subsystem reused by API and CLI
src/copilotmemory/memory/__init__.py - store · CRUD and persistence for memory records
src/copilotmemory/memory/store.py - embedder · Converts code and text into vector representations
src/copilotmemory/memory/embedder.py - retriever · Coordinates similarity lookup, ranking, and result filtering
src/copilotmemory/memory/retriever.py - vector store · Filesystem-backed semantic index used for embedding search
- SQLite meta · Local metadata store for timestamps, tags, and paths
Support
Configuration, logging, and package-level helpers
- config · Environment-driven storage, model, and server configuration
src/copilotmemory/utils/config.py - logger · Shared logging setup for runtime components
src/copilotmemory/utils/logger.py - pyproject · Build, dependency, and quality-check configuration
pyproject.toml - env example · Sample environment variables for local runtime configuration
.env.example
Quality
Documentation and tests that shape behavior
- architecture doc · Conceptual architecture and intended layering
docs/architecture.md - README · User-facing overview of setup, usage, and system flow
README.md - memory tests · Direct tests for core memory behavior
tests/test_memory.py
Connections 22
- copilotmemory → memory: reuses · Package exposes the shared domain subsystem
- copilotmemory → API routes: serves · Package includes HTTP delivery layer
- copilotmemory → CLI commands: serves · Package includes CLI delivery layer
- API routes → retriever: search · HTTP requests delegate to semantic retrieval
- API routes → store: crud · HTTP requests delegate to record persistence
- CLI commands → store: store · CLI writes memories through the domain store
- CLI commands → retriever: search · CLI search and prompt generation use retrieval
- retriever → embedder: embed query · Retrieval embeds natural-language queries
- retriever → store: read memory · Retrieval reads persisted records and vectors
- store → vector store: vectors · Semantic embeddings are kept in local vector storage
- store → SQLite meta: metadata · Operational fields are kept in SQLite metadata
- embedder → vector store: write vectors · Generated embeddings are stored for later similarity search
- config → API routes: binds · Config provides host and port settings
- config → CLI commands: drives · Config controls CLI behavior and serve mode
- config → store: paths · Config defines local database and vector paths
- logger → API routes: logs · Shared logging used by the API layer
- logger → CLI commands: logs · Shared logging used by CLI commands
- logger → memory: logs · Core services emit structured logs
- README → architecture doc: describes · README and architecture doc express intended system design
- memory tests → memory: verifies · Tests focus on core memory behavior
- pyproject → copilotmemory: builds · Project configuration defines packaging and quality tooling
- env example → config: documents · Example environment variables mirror runtime settings