Documentation
¶
Index ¶
- Constants
- func ContextLogger(ctx context.Context) *slog.Logger
- func NewRouter(prov llm.Provider, emb *embedder.Embedder, cfg *config.Config, ...) http.Handler
- func ProjectFromContext(ctx context.Context) string
- func RequestIDFromContext(ctx context.Context) string
- func SetBuildInfo(version, commit string)
- type ProjectStores
- type RouterOption
- type Storer
- type VectorIndexes
Constants ¶
const MaxImportEntries = 10_000
MaxImportEntries caps the number of archive entries importTar will process. Anything beyond this is treated as a potential zip-bomb / resource-exhaustion attempt and rejected with 413. (P0-3)
const MaxImportTotalBytes int64 = 500 << 20 // 500 MB
MaxImportTotalBytes caps the aggregate decompressed bytes across all entries in a single importTar request. Combined with MaxImportEntries this bounds memory + disk impact of a single import. (P0-3)
const MaxNoteBytes = 10 * 1024 * 1024
MaxNoteBytes caps the size of a single note body. Decision: 10 MB. Requests larger than this get a 413. The ceiling keeps us well below any SQLite single-row limit while accommodating very long design docs.
Variables ¶
This section is empty.
Functions ¶
func ContextLogger ¶ added in v0.1.0
ContextLogger returns slog.Default() enriched with the per-request ID when the context carries one. Handler trees that funnel log calls through this helper get free request-level log correlation; downstream code that needs the ID for metric labels should still read it via RequestIDFromContext(ctx) directly.
Callers that don't need the enrichment can keep using slog.Default() — the helper is additive, not mandatory.
func NewRouter ¶
func NewRouter(prov llm.Provider, emb *embedder.Embedder, cfg *config.Config, registry *project.Registry, opts ...RouterOption) http.Handler
NewRouter builds the single http.ServeMux with all routes.
Wave-2 signature change: the long-lived *store.Store positional argument is gone. Handlers resolve per-project stores via a shared Storer (the projectStores cache). Callers that want lifecycle control over that cache can inject it with WithProjectStores; otherwise one is created internally (leaked for process lifetime — fine for tests).
func ProjectFromContext ¶
ProjectFromContext returns the project slug stored on the request context. If no middleware ran (ctx is plain), returns the empty string. Handlers should treat empty as "fall back to cfg.DefaultProject" for defensive robustness.
func RequestIDFromContext ¶
RequestIDFromContext returns the ID attached by loggingMiddleware. Empty string when called from a context that never hit the middleware (e.g. a direct handler call from a test that skips the router wrapper).
func SetBuildInfo ¶
func SetBuildInfo(version, commit string)
SetBuildInfo publishes binary version + commit to the docsiq_build_info gauge. Kept with its pre-existing signature so cmd/serve.go callers do not have to change. Safe to call before the first scrape — obs.Init self-initialises.
Types ¶
type ProjectStores ¶
type ProjectStores projectStores
ProjectStores is the exported alias of *projectStores. Fields are intentionally unexported; callers interact with it through Storer (ForProject) and Close only.
func NewProjectStores ¶
func NewProjectStores(dataDir string) *ProjectStores
NewProjectStores is the public constructor used by cmd/serve to build a single cache that owns every per-project *store.Store handle for the server's lifetime. Closing the returned value releases every opened DB. Tests should use newProjectStores inside this package.
func (*ProjectStores) Close ¶
func (p *ProjectStores) Close() error
Close shuts down every cached store.
func (*ProjectStores) ForProject ¶
func (p *ProjectStores) ForProject(slug string) (*store.Store, error)
ForProject implements Storer on the exported alias.
func (*ProjectStores) Slugs ¶
func (p *ProjectStores) Slugs() []string
Slugs returns a snapshot of currently-cached project slugs.
type RouterOption ¶
type RouterOption func(*routerOptions)
RouterOption configures NewRouter. Zero-or-more options are appended to the existing positional arguments without breaking any existing call site.
func WithProjectStores ¶
func WithProjectStores(p *ProjectStores) RouterOption
WithProjectStores lets callers inject a pre-built ProjectStores cache so they can close it at shutdown. Nil (default) causes NewRouter to allocate its own — fine for tests, but real servers should supply one for controlled teardown.
func WithVectorIndexes ¶
func WithVectorIndexes(vi *VectorIndexes) RouterOption
WithVectorIndexes wires a per-project HNSW index cache into the search handlers and MCP server. Nil (default) makes LocalSearch fall back to brute-force per request.
func WithWorkq ¶ added in v0.1.0
func WithWorkq(p *workq.Pool) RouterOption
WithWorkq injects a bounded worker pool for background indexing jobs. When nil (default), upload() falls back to a detached goroutine — the dev/test path.
type Storer ¶
type Storer interface {
// ForProject opens (or returns the cached) *store.Store for slug.
// The caller MUST NOT call Close on the returned handle — the
// Storer owns lifecycle.
ForProject(slug string) (*store.Store, error)
}
Storer is the narrow resolver contract that doc handlers and MCP doc tools use to obtain a per-project *store.Store on every request. The implementation returned by newProjectStores is the production one; tests may substitute a map-backed fake.
Wave-2 policy: callers do NOT hold a long-lived *store.Store. Every handler invocation calls ForProject(slug) to get the correct DB for the request's project scope.
type VectorIndexes ¶
type VectorIndexes struct {
// contains filtered or unexported fields
}
VectorIndexes is a per-project cache of in-memory HNSW indexes. On first search against a slug the index is built from the store's (chunk, embedding) rows via vectorindex.BuildFromStore; subsequent searches reuse the cached index until Invalidate is called (e.g. at the end of an upload job).
A nil receiver is safe: ForProject returns nil which LocalSearch treats as the brute-force fallback. This lets tests skip index construction entirely.
func NewVectorIndexes ¶
func NewVectorIndexes() *VectorIndexes
NewVectorIndexes constructs an empty cache.
func (*VectorIndexes) ForProject ¶
func (v *VectorIndexes) ForProject(slug string, st *store.Store) vectorindex.Index
ForProject returns the cached index for slug, building one from st if no entry exists yet. A build error is logged and nil returned — LocalSearch falls back to brute-force, which is slow but correct.
Concurrent first-touch callers for the same slug are coalesced via singleflight — only one BuildFromStore runs; others wait on the same result.
func (*VectorIndexes) Invalidate ¶
func (v *VectorIndexes) Invalidate(slug string)
Invalidate evicts slug from the cache so the next ForProject call rebuilds from the latest store state. Called by the upload handler after a successful index + finalize cycle.
func (*VectorIndexes) Set ¶
func (v *VectorIndexes) Set(slug string, idx vectorindex.Index)
Set pre-populates the cache for slug. Used by cmd/serve to eagerly build indexes for every registered project at boot.