note

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package note contains the shared logic for persisting a user- or agent-authored note into the second-brain knowledge base. It is used by both the MCP add_note tool (cmd/mcp/main.go) and the POST /api/v1/notes REST handler (internal/api/notes.go), so a change here affects both paths identically — behaviour must not silently diverge between them.

Index

Constants

View Source
const MaxContentBytes = 10 * 1024 * 1024

MaxContentBytes is the upper bound for note content (10 MiB). Unchanged from the pre-extraction MCP add_note limit.

View Source
const MaxEmbedChunks = 2000

MaxEmbedChunks is the upper bound for the number of chunks embedded in a single Save call. Notes that produce more chunks are stored and indexed via FTS, but embedding is skipped to avoid unbounded API cost and long-running DB transactions.

View Source
const MaxTitleBytes = 1024

MaxTitleBytes is the upper bound for note title (1 KiB). Unchanged from the pre-extraction MCP add_note limit.

Variables

View Source
var ErrEmbedSkipped = errors.New("embedding skipped: chunk count exceeds limit")

ErrEmbedSkipped is returned by embedChunks when the chunk count exceeds MaxEmbedChunks. It is a sentinel that Save treats as a deliberate skip (non-fatal, non-success) rather than an actual embedding failure. Callers MUST NOT surface this as a user-facing error.

Functions

This section is empty.

Types

type ChunkWriter

type ChunkWriter interface {
	ReplaceDocument(ctx context.Context, documentID uuid.UUID, chunks []store.Chunk) error
	ListByDocument(ctx context.Context, documentID uuid.UUID) ([]store.Chunk, error)
	UpdateChunkEmbeddings(ctx context.Context, embeddings []store.ChunkEmbedding) error
}

ChunkWriter is the subset of ChunkStore used by Save.

type DocumentUpserter

type DocumentUpserter interface {
	Upsert(ctx context.Context, doc *model.Document) error
}

DocumentUpserter is the subset of DocumentStore used by Save.

type Embedder

type Embedder interface {
	Enabled() bool
	EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)
}

Embedder is the subset of EmbedClient used by Save.

type Result

type Result struct {
	ID               string `json:"id"`
	ChunksCreated    int    `json:"chunks_created"`
	EmbeddingCreated bool   `json:"embedding_created"`
}

Result is returned by Save on success.

func Save

func Save(
	ctx context.Context,
	docs DocumentUpserter,
	chunks ChunkWriter,
	embed Embedder,
	sourceType model.SourceType,
	title, content, sourceID string,
	metadata map[string]any,
	doEmbed bool,
	requireTitle bool,
) (*Result, string)

Save persists a note document, splits it into chunks, and optionally embeds those chunks. It is the extraction of the former cmd/mcp/main.go handleAddNote, parameterized so both the MCP add_note tool and the POST /api/v1/notes REST handler share identical persistence behaviour.

sourceType controls the stored model.SourceType (model.SourceAgentNote for MCP, model.SourceNote for the REST path — spec §6.2, updated 2026-08-25; MCP add_note previously wrote model.SourceLLMMemory, since deprecated).

requireTitle=true rejects an empty title (MCP add_note's pre-extraction behaviour). requireTitle=false allows an empty title, which POST /api/v1/notes relies on: the enrichment worker fills in the real title later rather than the server guessing one from content (spec §6.1).

Returns (result, "") on success, or (nil, errMsg) on failure.

Jump to

Keyboard shortcuts

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