Documentation
¶
Overview ¶
Package search maintains the full-text index and answers scoped queries.
The index holds derived, short-form documents rather than raw event JSON: the user's own prompt text, the agent's final replies, failed commands with their error head, shell commands without output, changed file paths, and session summaries. Every document points back to its source (kind + ref_id) for traceability.
Index ¶
- Constants
- Variables
- func Backfill(ctx context.Context, db *sql.DB) (int, error)
- func Delete(ctx context.Context, tx *sql.Tx, kind, refID string) error
- func IndexEvent(ctx context.Context, tx *sql.Tx, ev Event) error
- func MinSimilarities() (inject, searchFloor float64)
- func ResolveProject(ctx context.Context, db *sql.DB, owner, projectID, gitIdentity, name string) (string, error)
- func Search(ctx context.Context, db *sql.DB, ownerUserID string, req model.SearchRequest) (*model.SearchResponse, error)
- func SetSemantic(s Semantic)
- func Terms(expr string) []string
- func Upsert(ctx context.Context, tx *sql.Tx, d *Doc) error
- type Doc
- type Event
- type ProjectRef
- type Semantic
- type SemanticHit
Constants ¶
const ( KindPrompt = "prompt" KindReply = "reply" KindFailure = "failure" KindCommand = "command" KindChange = "change" KindSummary = "summary" KindMemory = "memory" )
Document kinds.
const ( MarkOpen = "\uE000" MarkClose = "\uE001" )
Snippet highlight markers. Brackets read well in terminals; the web UI asks for private-use code points, which cannot be confused with captured text.
Variables ¶
var ErrBadRequest = errors.New("bad search request")
ErrBadRequest marks invalid search requests.
Functions ¶
func Backfill ¶
Backfill indexes events that predate the search index. It runs once, at server start, and is idempotent.
func Delete ¶
Delete removes the document (kind, ref_id) from the index inside tx, if present; its vectors are removed later by the embedding sweep.
func IndexEvent ¶
IndexEvent indexes one event inside tx (no-op for events without a doc).
func MinSimilarities ¶
func MinSimilarities() (inject, searchFloor float64)
MinSimilarities returns the current semantic thresholds (see Semantic.MinSimilarities); zero when semantic search is off.
func ResolveProject ¶
func ResolveProject(ctx context.Context, db *sql.DB, owner, projectID, gitIdentity, name string) (string, error)
ResolveProject finds an existing project by ID, Git identity or name (the same matching rules as project creation), without creating one.
func Search ¶
func Search(ctx context.Context, db *sql.DB, ownerUserID string, req model.SearchRequest) (*model.SearchResponse, error)
Search runs req for the owner. Keyword search segments the query with jieba; results matching every term come first, then partial matches. When semantic search is available, its results are fused with the keyword results by Reciprocal Rank Fusion.
func SetSemantic ¶
func SetSemantic(s Semantic)
SetSemantic enables hybrid search (nil disables it). Called once at server start.
Types ¶
type Doc ¶
type Doc struct {
Kind string
RefID string // event_id, or session_id for summaries
ProjectID string
SessionID string
DeviceID string
AgentType string
OccurredAt time.Time
Title string
Body string
Files string
}
Doc is one searchable unit.
func DocFromEvent ¶
DocFromEvent derives the searchable document for an event, or nil when the event carries nothing worth finding later.
type Event ¶
type Event struct {
EventID string
EventType string
ProjectID string
SessionID string
DeviceID string
AgentType string
OccurredAt time.Time
Payload []byte
}
Event is the subset of an ingested event the indexer needs.
type ProjectRef ¶
type ProjectRef struct {
ID string `json:"project_id,omitempty"`
GitIdentity string `json:"git_identity,omitempty"`
Name string `json:"project_name,omitempty"`
Cwd string `json:"cwd,omitempty"`
}
ProjectRef identifies a project the way different callers can: by ID, by Git identity or name (clients that inspect their working directory), or by a working directory on the calling device (remote MCP tools, which cannot inspect the caller's filesystem but know the agent's cwd).
type Semantic ¶
type Semantic interface {
SemanticSearch(ctx context.Context, query string, projectIDs []string, k int) ([]SemanticHit, error)
// MinSimilarities returns the model's thresholds: for injecting a
// meaning-only match into an agent's context, and for keeping it in
// search results at all.
MinSimilarities() (inject, searchFloor float64)
}
Semantic finds documents similar in meaning to a query. It returns no hits (and no error) when semantic search is unavailable at the moment.
type SemanticHit ¶
SemanticHit is a document found by vector similarity.