store

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CollectionChunks = "nb_chunks"
	CollectionLinks  = "nb_links"
)

Variables

This section is empty.

Functions

func CombineWhereFilters

func CombineWhereFilters(f1, f2 chroma.WhereFilter) chroma.WhereFilter

CombineWhereFilters safely combines two optional WhereFilters using And.

func ObsidianURI

func ObsidianURI(vaultName, filePath string) string

ObsidianURI builds an obsidian://open URI for a vault-relative file path.

func TagWhereClause

func TagWhereClause(tag string) chroma.WhereClause

TagWhereClause constructs a Chroma Or filter matching tag against tag_0 through tag_19.

Types

type BatchIngestData

type BatchIngestData struct {
	NoteSlug     string
	ChunkRecords []ChunkRecord
	Links        []string
}

type ChunkRecord

type ChunkRecord struct {
	ID           string // "<slug>:<index>"
	NoteSlug     string
	Title        string
	FilePath     string
	ChunkIndex   int
	Text         string
	Tags         []string
	HasLinks     bool
	HeadingPath  string
	HeadingLevel int
	CodeBlocks   int
	HasTable     bool
	HasTask      bool
	ModifiedMs   int64
	ContentHash  string
	Embedding    []float32
}

type ChunkWindow

type ChunkWindow struct {
	MatchedIndex int      `json:"matched_index"`
	Texts        []string `json:"texts"`
	Indices      []int    `json:"indices"`
}

ChunkWindow contains a matched chunk with its surrounding context.

type NoteContent

type NoteContent struct {
	NoteSlug string   `json:"note_slug"`
	Title    string   `json:"title"`
	FilePath string   `json:"file_path"`
	Tags     []string `json:"tags,omitempty"`
	Text     string   `json:"text"`
	Chunks   int      `json:"chunks"`
}

NoteContent represents the complete reconstructed text and metadata of a note.

type Result

type Result struct {
	NoteSlug    string   `json:"note_slug"`
	Title       string   `json:"title"`
	FilePath    string   `json:"file_path"`
	Score       float64  `json:"score"`
	IsPhantom   bool     `json:"is_phantom,omitempty"`
	ChunkIndex  int      `json:"chunk_index,omitempty"`
	Tags        []string `json:"tags,omitempty"`
	Extra       string   `json:"extra,omitempty"` // e.g. shared tags, hop count
	HeadingPath string   `json:"heading_path,omitempty"`
	Text        string   `json:"text,omitempty"`    // populated only when include-text is requested
	Context     []string `json:"context,omitempty"` // adjacent chunks when windowing is enabled
}

Result is one row returned by any query.

type Store

type Store struct {
	SkipAttachments bool
	// contains filtered or unexported fields
}

Store wraps two ChromaDB collections.

func Open

func Open(ctx context.Context, path string) (*Store, error)

Open creates or opens the persistent ChromaDB store at path.

func (s *Store) Backlinks(ctx context.Context, targetSlug string) ([]Result, error)

Backlinks returns all notes that link TO targetSlug.

func (*Store) BatchIngest

func (s *Store) BatchIngest(ctx context.Context, data []BatchIngestData, staleSlugs []string) error

BatchIngest atomically replaces all chunks and links for a batch of notes, and deletes stale notes. It uses a single mutex lock to serialize operations on the store.

func (*Store) Close

func (s *Store) Close() error

Close releases all resources.

func (*Store) Connections

func (s *Store) Connections(ctx context.Context, seedSlug string, maxHops int) ([]Result, error)

Connections finds notes reachable from seedSlug within maxHops. BFS implemented in Go (no recursive SQL needed).

func (*Store) DeleteNoteChunks

func (s *Store) DeleteNoteChunks(ctx context.Context, noteSlug string) error

DeleteNoteChunks removes all chunks belonging to a note (before re-ingest).

func (s *Store) DeleteNoteLinks(ctx context.Context, noteSlug string) error

DeleteNoteLinks removes all outgoing links for a note.

func (*Store) GetChunkWindow

func (s *Store) GetChunkWindow(ctx context.Context, noteSlug string, chunkIndex int, windowSize int) (*ChunkWindow, error)

GetChunkWindow fetches ±windowSize adjacent chunks around the given chunk index.

func (*Store) GetNote

func (s *Store) GetNote(ctx context.Context, slugOrPath string) (*NoteContent, error)

GetNote retrieves all chunks of a note and reconstructs its complete content.

func (*Store) GetNoteHashes

func (s *Store) GetNoteHashes(ctx context.Context) (map[string]string, error)

GetNoteHashes fetches the content_hash for all notes by reading chunk_index=0. Returns a map of note_slug -> content_hash.

func (*Store) GraphBoostedSearch

func (s *Store) GraphBoostedSearch(ctx context.Context, queryVec []float32, seedSlug string, boost float64, limit int, includeText bool) ([]Result, error)

GraphBoostedSearch runs semantic search, then boosts scores of notes directly linked to/from seedSlug.

func (*Store) HiddenConnections

func (s *Store) HiddenConnections(ctx context.Context, queryVec []float32, seedSlug string, limit int, includeText bool) ([]Result, error)

HiddenConnections finds notes semantically similar to queryVec but NOT already linked to/from seedSlug.

func (*Store) IngestNote

func (s *Store) IngestNote(ctx context.Context, noteSlug string, chunks []ChunkRecord, links []string) error

IngestNote atomically replaces all chunks and links for a single note. It holds the store mutex for the entire Delete→UpsertChunks→UpsertLinks sequence to prevent concurrent hnswlib modifications that corrupt the HNSW graph (assertion: inbound_connections_num[i] > 0).

func (*Store) PopulateContext

func (s *Store) PopulateContext(ctx context.Context, results []Result, windowSize int)

PopulateContext fetches adjacent chunks for each result when windowSize > 0.

func (*Store) Reset

func (s *Store) Reset(ctx context.Context) error

Reset drops and recreates both collections. Used by `notebrain reset`.

func (*Store) SemanticSearch

func (s *Store) SemanticSearch(ctx context.Context, queryVec []float32, limit int, topKPerNote int, whereFilter chroma.WhereFilter, includeText bool) ([]Result, error)

SemanticSearch finds the most similar chunks to queryVec. Returns deduplicated chunks retaining up to topKPerNote chunks per note.

func (*Store) SharedTags

func (s *Store) SharedTags(ctx context.Context, noteSlug string, minShared int) ([]Result, error)

SharedTags finds notes sharing at least minShared tags with noteSlug.

func (*Store) Stats

func (s *Store) Stats(ctx context.Context) (map[string]int64, error)

Stats returns document counts for both collections.

func (*Store) TagSearch

func (s *Store) TagSearch(ctx context.Context, tag string, limit int, whereFilter chroma.WhereFilter, includeText bool) ([]Result, error)

TagSearch finds notes that match a specific tag name.

func (*Store) UpsertChunks

func (s *Store) UpsertChunks(ctx context.Context, chunks []ChunkRecord) error

UpsertChunks stores a batch of chunks (upsert = insert or replace by ID). Call DeleteNoteChunks first to cleanly re-ingest a note.

func (s *Store) UpsertLinks(ctx context.Context, noteSlug string, links []string) error

UpsertLinks replaces all outgoing links for a note.

Jump to

Keyboard shortcuts

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