api

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: MIT Imports: 30 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 api wires together the HTTP router, middleware, and handlers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DocumentStore

type DocumentStore interface {
	GetByID(ctx context.Context, id uuid.UUID) (*model.Document, error)
	ListBySource(ctx context.Context, src model.SourceType, limit, offset int) ([]*model.Document, error)
	ListRecent(ctx context.Context, includeSrc model.SourceType, excludeSrcs []model.SourceType, limit, offset int) ([]*model.Document, error)
	CountBySource(ctx context.Context) (map[string]int, error)
	QueryBaselineStats(ctx context.Context) (*store.BaselineStats, error)
}

DocumentStore is the subset of store.DocumentStore used by the API.

type EvalExporter

type EvalExporter interface {
	ExportJSONL(ctx context.Context, w io.Writer) (int, error)
}

EvalExporter is the subset of store.EvalStore used by the eval export handler. Defined as an interface so tests can inject a stub without a real database.

type EvalMetricsLister

type EvalMetricsLister interface {
	List(ctx context.Context, limit int) ([]store.EvalMetricsRecord, error)
}

EvalMetricsLister is the subset of store.EvalMetricsStore used by the eval metrics handler. Defined as an interface so tests can inject a stub.

type FeedbackRecorder

type FeedbackRecorder interface {
	Record(ctx context.Context, f store.Feedback) (int64, error)
}

FeedbackRecorder is the subset of store.FeedbackStore used by the feedback handler. Defined as an interface so tests can inject a stub without a real database.

type FeedbackRequest

type FeedbackRequest struct {
	Query      *string        `json:"query,omitempty"`
	DocumentID *string        `json:"document_id,omitempty"`
	ChunkID    *int64         `json:"chunk_id,omitempty"`
	Source     string         `json:"source"`
	SessionID  *string        `json:"session_id,omitempty"`
	UserID     *string        `json:"user_id,omitempty"`
	Thumbs     int16          `json:"thumbs"`
	Comment    *string        `json:"comment,omitempty"`
	Metadata   map[string]any `json:"metadata,omitempty"`
}

FeedbackRequest is the JSON body accepted by POST /api/v1/feedback.

type FeedbackResponse

type FeedbackResponse struct {
	ID int64 `json:"id"`
}

FeedbackResponse is returned on successful feedback creation.

type IngestFileChunkWriter added in v0.17.0

type IngestFileChunkWriter 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
}

IngestFileChunkWriter is the chunk persistence interface required by the ingest-file handler. *store.ChunkStore satisfies this interface.

type IngestFileEmbedder added in v0.17.0

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

IngestFileEmbedder is the embedding interface required by the ingest-file handler. The search.EmbeddingEngine satisfies this interface.

type IngestFileResponse added in v0.17.0

type IngestFileResponse struct {
	DocumentID string `json:"document_id"`
	Accepted   bool   `json:"accepted"`
}

IngestFileResponse is the JSON body returned on a successful upload.

type IngestFileUpserter added in v0.17.0

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

IngestFileUpserter is the document persistence interface required by the ingest-file handler. *store.DocumentStore satisfies this interface.

type ReindexRecommender

type ReindexRecommender interface {
	Check(ctx context.Context) (search.ReindexRecommendation, error)
}

ReindexRecommender is the subset of search.ReindexChecker used by the reindex check handler. Defined as an interface so tests can inject a stub.

type ReindexStateRecorder

type ReindexStateRecorder interface {
	Save(ctx context.Context, state store.ReindexState) error
}

ReindexStateRecorder is the subset of store.ReindexStateStore used by the reindex handler. Defined as an interface so tests can inject a stub.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server holds the dependencies needed by all handlers.

func NewServer

func NewServer(
	docs DocumentStore,
	svc *search.Service,
	feedback FeedbackRecorder,
	eval EvalExporter,
	llmClient llm.Completer,
	filesystemPath string,
	apiKey string,
) *Server

NewServer creates a Server with the provided dependencies.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the root http.Handler for the application. It is safe to call from multiple goroutines: the underlying router is built exactly once via sync.Once and the result is reused for every subsequent call.

func (*Server) WithEvalMetrics

func (s *Server) WithEvalMetrics(em EvalMetricsLister) *Server

WithEvalMetrics attaches an EvalMetricsLister to the server so that the GET /api/v1/eval/metrics route is registered. Returns s for method chaining.

NOTE: WithEvalMetrics must be called before the first call to Handler(), because the chi router is built exactly once via sync.Once.

func (*Server) WithIngestFile added in v0.17.0

func (s *Server) WithIngestFile(
	upserter IngestFileUpserter,
	chunks IngestFileChunkWriter,
	embed IngestFileEmbedder,
	maxFileBytes int64,
) *Server

WithIngestFile attaches the dependencies required by POST /api/v1/ingest/file and enables the route.

maxFileBytes is the per-upload size cap in bytes; 0 uses the package default (100 MiB). Pass cfg.IngestMaxFileBytes here.

Must be called before the first call to Handler().

func (*Server) WithReindexCheck

func (s *Server) WithReindexCheck(rc ReindexRecommender) *Server

WithReindexCheck attaches a ReindexRecommender to the server so that the GET /api/v1/reindex/check route is registered. Returns s for method chaining.

NOTE: WithReindexCheck must be called before the first call to Handler(), because the chi router is built exactly once via sync.Once.

func (*Server) WithReindexState

func (s *Server) WithReindexState(rs ReindexStateRecorder) *Server

WithReindexState attaches a ReindexStateRecorder to the server so that the /api/v1/reindex route is registered. Returns s for method chaining.

NOTE: WithReindexState must be called before the first call to Handler(), because the chi router is built exactly once via sync.Once.

Jump to

Keyboard shortcuts

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