searchv1

import searchv1 "pocketone.dev/ext/contracts/llm/search/v1"

Package searchv1 is the llm.search/v1 contract: named buckets of content an app searches. An app makes the bucket it needs (Ensure); its admins fill it from the dashboard's Search screen. A bucket holds sources, each one tracked unit however many documents it brings: a file, pasted text, a folder, a zip, a web page, a Git repository or one of the app's collections, or a folder on the server. Adding a source of the same name again replaces it: unchanged documents cost nothing, missing ones go. URL, repository and collection sources keep themselves current. The provider splits each document into chunks with their source (document, section, lines, record), embeds them with the app's one embedding model (llm.embed/v1, picked automatically; identical chunks anywhere in the app are embedded once), and returns the chunks that best match a query across the buckets asked for.

A wire contract at /api/_c/llm.search/v1. In page code it's $llm.search (bound by the llm extension); llm.text/v1 and llm.chat/v1 calls take `enrich` to add a search's best passages to their prompt (Enrich).

Source: ext/contracts/llm/search/v1.

Constants

const (
	EnrichDefault = 5
	EnrichMax     = 20
)

EnrichDefault and EnrichMax are how many passages an Enrich adds by default, and at most.

const (
	KindFile       = "file"       // one dropped or uploaded file
	KindText       = "text"       // pasted text
	KindFolder     = "folder"     // a dropped folder, file by file
	KindDir        = "dir"        // a folder of the app's files on the server, read again every few minutes
	KindZip        = "zip"        // a zip, a document per text file inside
	KindPage       = "page"       // a web page, fetched
	KindGit        = "git"        // a Git repository: the default branch's files and recent commits
	KindCollection = "collection" // one of the app's collections, a document per record
)

Source kinds.

const (
	EveryHour = "hour"
	EveryDay  = "day"
	EveryWeek = "week"
)

Refresh intervals for URL and repository sources.

Variables

var (
	ErrNoBucket    = &extkit.Error{Code: "not_found", Status: 404, Message: "no bucket with that name"}
	ErrNoSource    = &extkit.Error{Code: "not_found", Status: 404, Message: "no source with that name in the bucket"}
	ErrInvalidName = &extkit.Error{Code: "bad_request", Status: 400, Message: "a bucket name is letters, digits, - and _, at most 64, starting with a letter or digit"}
	ErrTooLarge    = &extkit.Error{Code: "too_large", Status: 413, Message: "over the bucket's limit"}
	ErrNotText     = &extkit.Error{Code: "bad_request", Status: 400, Message: "only text files (Markdown, text, code) or a zip of them can be added"}
	ErrNoModel     = &extkit.Error{Code: "not_configured", Status: 503, Message: "no embedding model: add an AI provider with embedding models in Settings → LLM"}
)

Errors.

var Contract = extkit.NewContract[Search]("llm.search/v1", extkit.One).JS(extkit.JSHooks, nil).JSTypes(jsTypes)

Contract is llm.search/v1.

var ErrNoSearch = &extkit.Error{Code: "not_configured", Status: 503, Message: "enrich needs search buckets (llm.search/v1), and none are on this app"}

ErrNoSearch: a call asked to enrich its prompt, but nothing provides llm.search/v1 on the app.

var W = extkit.NewWire(Contract, "search", func(inner Search, g *extkit.Guard[Search]) Search {
	return &guardSearch{inner, g}
},
	extkit.Op[Search]{
		Name:   "status",
		Desc:   "Is the app's embedding model and how far embedding has got across every bucket.",
		Method: "GET",
		Path:   "status",
		Scope:  "search:read",
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			return impl.Status(ctx, a)
		},
	},
	extkit.Op[Search]{
		Name:   "set_model",
		Desc:   "Changes the app's embedding model (\"provider/model\" from llm.embed/v1's models; \"\" picks one again). Every bucket is embedded again in the background; until a chunk is, keywords still find it.",
		Method: "POST",
		Path:   "set-model",
		In:     reflect.TypeOf(ModelInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in ModelInput
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.SetModel(ctx, a, in)
		},
	},
	extkit.Op[Search]{
		Name:   "buckets",
		Desc:   "Lists the app's buckets with their counts.",
		Method: "GET",
		Path:   "buckets",
		Scope:  "search:read",
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			return impl.Buckets(ctx, a)
		},
	},
	extkit.Op[Search]{
		Name:   "bucket",
		Desc:   "Returns one bucket with its counts.",
		Method: "GET",
		Path:   "bucket",
		Scope:  "search:read",
		In:     reflect.TypeOf(Ref{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in Ref
			if err := extkit.DecodeQuery(req.Query, &in); err != nil {
				return nil, err
			}
			return impl.Bucket(ctx, a, in)
		},
	},
	extkit.Op[Search]{
		Name:   "ensure",
		Desc:   "Makes a bucket if it's missing and returns it. An existing bucket keeps its settings, except that an empty title, description or owner is filled in. Apps call it at startup for the bucket they need.",
		Method: "POST",
		Path:   "ensure",
		In:     reflect.TypeOf(EnsureInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in EnsureInput
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Ensure(ctx, a, in)
		},
	},
	extkit.Op[Search]{
		Name:   "update",
		Desc:   "Changes a bucket's title, description or limits (fields left out stay).",
		Method: "POST",
		Path:   "update",
		In:     reflect.TypeOf(UpdateInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in UpdateInput
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Update(ctx, a, in)
		},
	},
	extkit.Op[Search]{
		Name:   "delete",
		Desc:   "Removes a bucket and everything in it.",
		Method: "POST",
		Path:   "delete",
		In:     reflect.TypeOf(Ref{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in Ref
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Delete(ctx, a, in)
		},
	},
	extkit.Op[Search]{
		Name:   "sources",
		Desc:   "Lists a bucket's sources, by name.",
		Method: "GET",
		Path:   "sources",
		Scope:  "search:read",
		In:     reflect.TypeOf(BucketRef{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in BucketRef
			if err := extkit.DecodeQuery(req.Query, &in); err != nil {
				return nil, err
			}
			return impl.Sources(ctx, a, in)
		},
	},
	extkit.Op[Search]{
		Name:   "add",
		Desc:   "Puts a file or pasted text in a bucket as its own source (one document), replacing the source of that name. The same text again costs nothing; changed text embeds only its new chunks. It returns at once; the document is embedded in the background (its status says how far it got).",
		Method: "POST",
		Path:   "add",
		In:     reflect.TypeOf(AddInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in AddInput
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Add(ctx, a, in)
		},
	},
	extkit.Op[Search]{
		Name:   "upload",
		Desc:   "Adds a file sent as the request body: ?bucket=<name>&name=<file name>[&replace=<source>]. A .zip is one source with a document per text file inside it; anything else is a file source.",
		Method: "POST",
		Path:   "upload",
		RawIn:  true,
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			in := extkit.RawIn{Query: req.Query, Body: req.Body, ContentType: req.ContentType, Header: req.Header}
			return impl.Upload(ctx, a, in)
		},
	},
	extkit.Op[Search]{
		Name:   "put",
		Desc:   "Adds one file to a folder source (made on the first one), the way the dashboard sends a dropped folder; Prune ends it.",
		Method: "POST",
		Path:   "put",
		In:     reflect.TypeOf(PutInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in PutInput
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Put(ctx, a, in)
		},
	},
	extkit.Op[Search]{
		Name:   "prune",
		Desc:   "Removes the documents of a folder source that aren't in Keep: the files the folder no longer has.",
		Method: "POST",
		Path:   "prune",
		In:     reflect.TypeOf(PruneInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in PruneInput
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Prune(ctx, a, in)
		},
	},
	extkit.Op[Search]{
		Name:   "add_u_r_l",
		Desc:   "Adds a web page or a Git repository as a source (named by its URL, replacing one of that name) and reads it in the background; Every keeps it current.",
		Method: "POST",
		Path:   "add-url",
		In:     reflect.TypeOf(URLInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in URLInput
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.AddURL(ctx, a, in)
		},
	},
	extkit.Op[Search]{
		Name:   "add_folder",
		Desc:   "Adds a folder of the app's own files on the server (named by its path, replacing one of that name): every text file in it, read in the background and read again every few minutes, so changed files are embedded again and removed ones leave. With URL, each result from it links to the page that file is published at.",
		Method: "POST",
		Path:   "add-folder",
		In:     reflect.TypeOf(FolderInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in FolderInput
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.AddFolder(ctx, a, in)
		},
	},
	extkit.Op[Search]{
		Name:   "detect_u_r_l",
		Desc:   "Says how AddURL would read a URL: as a Git repository when its server answers the Git protocol (any host, with or without .git), otherwise as a web page.",
		Method: "POST",
		Path:   "detect-url",
		Scope:  "search:read",
		In:     reflect.TypeOf(URLRef{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in URLRef
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.DetectURL(ctx, a, in)
		},
	},
	extkit.Op[Search]{
		Name:   "follow",
		Desc:   "Adds one of the app's collections as a source (named by the collection): each record the filter keeps is a document, kept in sync as records are saved and deleted.",
		Method: "POST",
		Path:   "follow",
		In:     reflect.TypeOf(FollowInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in FollowInput
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Follow(ctx, a, in)
		},
	},
	extkit.Op[Search]{
		Name:   "refresh",
		Desc:   "Reads a source again now: fetches a URL or repository, rereads a collection, resplits a file or zip.",
		Method: "POST",
		Path:   "refresh",
		In:     reflect.TypeOf(SourceRef{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in SourceRef
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Refresh(ctx, a, in)
		},
	},
	extkit.Op[Search]{
		Name:   "remove",
		Desc:   "Takes sources out of a bucket, with their documents.",
		Method: "POST",
		Path:   "remove",
		In:     reflect.TypeOf(RemoveInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in RemoveInput
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Remove(ctx, a, in)
		},
	},
	extkit.Op[Search]{
		Name:   "documents",
		Desc:   "Lists a bucket's documents (or one source's), by source and name.",
		Method: "GET",
		Path:   "documents",
		Scope:  "search:read",
		In:     reflect.TypeOf(DocumentsInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in DocumentsInput
			if err := extkit.DecodeQuery(req.Query, &in); err != nil {
				return nil, err
			}
			return impl.Documents(ctx, a, in)
		},
	},
	extkit.Op[Search]{
		Name:   "search",
		Desc:   "Returns the chunks that best match a query across the buckets named, best first.",
		Method: "POST",
		Path:   "search",
		Scope:  "search:read",
		In:     reflect.TypeOf(SearchInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in SearchInput
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Search(ctx, a, in)
		},
	},
	extkit.Op[Search]{
		Name:   "sample",
		Desc:   "Returns chunks picked at random from the buckets named: material to draw from (\"surprise me\", a topic nobody asked about), not matches. No query, no embedding, so it costs nothing. Like Search without a viewer, it may return any chunk, a followed record's included.",
		Method: "POST",
		Path:   "sample",
		Scope:  "search:read",
		In:     reflect.TypeOf(SampleInput{}),
		Out:    extkit.OutJSON,
		Invoke: func(ctx context.Context, impl Search, a extkit.Auth, req extkit.OpRequest) (any, error) {
			var in SampleInput
			if err := extkit.DecodeInput(req.JSON, &in); err != nil {
				return nil, err
			}
			return impl.Sample(ctx, a, in)
		},
	},
)

W is llm.search/v1's wire side: routes at /api/_c/llm.search/v1/<op>, action hooks, MCP tools and the client.

Functions

Enrich

func Enrich(ctx context.Context, app core.App, e *llm.Enrich, query string) (string, []llm.Passage, error)

Enrich runs e's search on app (with query when e.Query is empty) and returns the text a model call sends after its prompt, and the passages in it. It's how llm.text/v1 and llm.chat/v1 providers fulfil `enrich`, so every provider adds passages the same way. With no buckets named it returns nothing; with no matches, no text.

OnAdd

func OnAdd(owner any, fn func(e *extkit.CallEvent, in *AddInput) error)

OnAdd binds fn to add calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnAddFolder

func OnAddFolder(owner any, fn func(e *extkit.CallEvent, in *FolderInput) error)

OnAddFolder binds fn to add_folder calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnAddURL

func OnAddURL(owner any, fn func(e *extkit.CallEvent, in *URLInput) error)

OnAddURL binds fn to add_u_r_l calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnBucket

func OnBucket(owner any, fn func(e *extkit.CallEvent, in *Ref) error)

OnBucket binds fn to bucket calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnBuckets

func OnBuckets(owner any, fn func(e *extkit.CallEvent) error)

OnBuckets binds fn to buckets calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse.

OnDelete

func OnDelete(owner any, fn func(e *extkit.CallEvent, in *Ref) error)

OnDelete binds fn to delete calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnDetectURL

func OnDetectURL(owner any, fn func(e *extkit.CallEvent, in *URLRef) error)

OnDetectURL binds fn to detect_u_r_l calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnDocuments

func OnDocuments(owner any, fn func(e *extkit.CallEvent, in *DocumentsInput) error)

OnDocuments binds fn to documents calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnEnsure

func OnEnsure(owner any, fn func(e *extkit.CallEvent, in *EnsureInput) error)

OnEnsure binds fn to ensure calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnFollow

func OnFollow(owner any, fn func(e *extkit.CallEvent, in *FollowInput) error)

OnFollow binds fn to follow calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnPrune

func OnPrune(owner any, fn func(e *extkit.CallEvent, in *PruneInput) error)

OnPrune binds fn to prune calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnPut

func OnPut(owner any, fn func(e *extkit.CallEvent, in *PutInput) error)

OnPut binds fn to put calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnRefresh

func OnRefresh(owner any, fn func(e *extkit.CallEvent, in *SourceRef) error)

OnRefresh binds fn to refresh calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnRemove

func OnRemove(owner any, fn func(e *extkit.CallEvent, in *RemoveInput) error)

OnRemove binds fn to remove calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnSample

func OnSample(owner any, fn func(e *extkit.CallEvent, in *SampleInput) error)

OnSample binds fn to sample calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnSearch

func OnSearch(owner any, fn func(e *extkit.CallEvent, in *SearchInput) error)

OnSearch binds fn to search calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnSetModel

func OnSetModel(owner any, fn func(e *extkit.CallEvent, in *ModelInput) error)

OnSetModel binds fn to set_model calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnSources

func OnSources(owner any, fn func(e *extkit.CallEvent, in *BucketRef) error)

OnSources binds fn to sources calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnStatus

func OnStatus(owner any, fn func(e *extkit.CallEvent) error)

OnStatus binds fn to status calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse.

OnUpdate

func OnUpdate(owner any, fn func(e *extkit.CallEvent, in *UpdateInput) error)

OnUpdate binds fn to update calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

OnUpload

func OnUpload(owner any, fn func(e *extkit.CallEvent, in *extkit.RawIn) error)

OnUpload binds fn to upload calls on owner (an app, or a host's scope for calls the host answers). Call e.Next() to continue; return an error to refuse. in is the call's input; changes reach the provider.

Types

AddInput

type AddInput struct {
	Bucket string `json:"bucket"`
	// Name is the source's (and its document's) name, usually a file name ("install.md"). Its extension picks the
	// splitter: Markdown by headings, code and the rest by blank lines.
	Name string `json:"name"`
	Text string `json:"text"`
	// Kind is file (the default) or text, for the dashboard.
	Kind string `json:"kind,omitempty"`
	// Replace names an existing source this one replaces under the new name (a renamed new version: notes-v2.zip
	// for notes-v1.zip). Without it, only a source of the same name is replaced.
	Replace string `json:"replace,omitempty"`
}

AddInput is a file or pasted text.

Bucket

type Bucket struct {
	// Name is the bucket's id: letters, digits, - and _, starting with a letter or digit (at most 64).
	Name  string `json:"name"`
	Title string `json:"title"`
	// Description says what belongs in the bucket: the app that made it tells its admins what to load.
	Description  string    `json:"description"`
	Owner        string    `json:"owner"` // who made it (the app's name, say), for the dashboard
	MaxDocuments int       `json:"maxDocuments"`
	MaxBytes     int64     `json:"maxBytes"`
	Sources      int       `json:"sources"`
	Documents    int       `json:"documents"`
	Chunks       int       `json:"chunks"`
	Bytes        int64     `json:"bytes"`
	Pending      int       `json:"pending"` // documents waiting to be embedded
	Errors       int       `json:"errors"`  // documents or sources that failed
	Created      time.Time `json:"created"`
	Updated      time.Time `json:"updated"`
}

Bucket is a named set of sources searched together.

BucketList

type BucketList struct {
	Buckets []Bucket `json:"buckets"`
}

BucketList is every bucket, by name.

BucketRef

type BucketRef struct {
	Bucket string `json:"bucket"`
}

BucketRef names a bucket, for operations on its sources.

Client

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

Client is llm.search/v1 over HTTP, for the CLI and other apps. It implements Search; the token it was made with is the credential, so the extkit.Auth argument is ignored.

NewClient

func NewClient(baseURL, token string, hc *http.Client) *Client

NewClient calls llm.search/v1 on the app at baseURL with token (a PocketBase auth token or an API token).

Client.Add

func (c *Client) Add(ctx context.Context, _ extkit.Auth, in AddInput) (Source, error)

Client.AddFolder

func (c *Client) AddFolder(ctx context.Context, _ extkit.Auth, in FolderInput) (Source, error)

Client.AddURL

func (c *Client) AddURL(ctx context.Context, _ extkit.Auth, in URLInput) (Source, error)

Client.Bucket

func (c *Client) Bucket(ctx context.Context, _ extkit.Auth, in Ref) (Bucket, error)

Client.Buckets

func (c *Client) Buckets(ctx context.Context, _ extkit.Auth) (BucketList, error)

Client.Delete

func (c *Client) Delete(ctx context.Context, _ extkit.Auth, in Ref) (Removed, error)

Client.DetectURL

func (c *Client) DetectURL(ctx context.Context, _ extkit.Auth, in URLRef) (URLKind, error)

Client.Documents

func (c *Client) Documents(ctx context.Context, _ extkit.Auth, in DocumentsInput) (DocumentList, error)

Client.Ensure

func (c *Client) Ensure(ctx context.Context, _ extkit.Auth, in EnsureInput) (Bucket, error)

Client.Follow

func (c *Client) Follow(ctx context.Context, _ extkit.Auth, in FollowInput) (Source, error)

Client.Prune

func (c *Client) Prune(ctx context.Context, _ extkit.Auth, in PruneInput) (Source, error)

Client.Put

func (c *Client) Put(ctx context.Context, _ extkit.Auth, in PutInput) (Document, error)

Client.Refresh

func (c *Client) Refresh(ctx context.Context, _ extkit.Auth, in SourceRef) (Source, error)

Client.Remove

func (c *Client) Remove(ctx context.Context, _ extkit.Auth, in RemoveInput) (Removed, error)

Client.Sample

func (c *Client) Sample(ctx context.Context, _ extkit.Auth, in SampleInput) (Results, error)

Client.Search

func (c *Client) Search(ctx context.Context, _ extkit.Auth, in SearchInput) (Results, error)

Client.SetModel

func (c *Client) SetModel(ctx context.Context, _ extkit.Auth, in ModelInput) (Status, error)

Client.Sources

func (c *Client) Sources(ctx context.Context, _ extkit.Auth, in BucketRef) (SourceList, error)

Client.Status

func (c *Client) Status(ctx context.Context, _ extkit.Auth) (Status, error)

Client.Update

func (c *Client) Update(ctx context.Context, _ extkit.Auth, in UpdateInput) (Bucket, error)

Client.Upload

func (c *Client) Upload(ctx context.Context, _ extkit.Auth, in extkit.RawIn) (Source, error)

Document

type Document struct {
	Bucket string `json:"bucket"`
	Source string `json:"source"`
	Name   string `json:"name"` // its path in the source, the URL, "commit <sha>" or "<collection>/<id>"
	Kind   string `json:"kind"` // markdown, code or text: how it was split
	Size   int64  `json:"size"`
	Hash   string `json:"hash"` // sha256 of the text
	// Status is queued (waiting to be embedded), embedding, ready or error.
	Status string `json:"status"`
	Error  string `json:"error,omitempty"`
	Chunks int    `json:"chunks"`
	// Embedded is how many of its chunks have the app's model's vectors (Chunks when it's ready).
	Embedded     int        `json:"embedded"`
	Record       *RecordRef `json:"record,omitempty"` // the record it was made from, in a collection source
	Tokens       int        `json:"tokens"`           // the text's estimated size in tokens
	CostMicroUSD int64      `json:"costMicroUSD"`     // what embedding it has cost so far
	Created      time.Time  `json:"created"`
	Updated      time.Time  `json:"updated"`
}

Document is one piece of a source: a file, a page, a commit or a record.

DocumentList

type DocumentList struct {
	Documents []Document `json:"documents"`
}

DocumentList is a bucket's documents.

DocumentsInput

type DocumentsInput struct {
	Bucket string `json:"bucket"`
	Source string `json:"source,omitempty"` // only this source's
	Prefix string `json:"prefix,omitempty"` // only names starting with it
}

DocumentsInput picks a bucket's documents.

EnsureInput

type EnsureInput struct {
	Name        string `json:"name"`
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	Owner       string `json:"owner,omitempty"`
}

EnsureInput is the bucket an app needs.

FolderInput

type FolderInput struct {
	Bucket string `json:"bucket"`
	// Path is the folder, relative to the app's own folder (the one holding pb_data, pb_pages and pb_public); it can't
	// leave that folder or be pb_data. "pb_pages/docs", say.
	Path string `json:"path"`
	// Include keeps only files matching one of these patterns (against the file name or its path in the folder:
	// "*.md"); none keeps every text file. Exclude leaves out matches, beside what's always skipped (dot folders and
	// dotfiles, node_modules, vendor, lockfiles, binaries).
	Include []string `json:"include,omitempty"`
	Exclude []string `json:"exclude,omitempty"`
	// URL is where each file is published, with {path} for the file's path in the folder without its extension (an
	// index file is its folder): "/docs/{path}" makes guides/install.md /docs/guides/install and guides/index.md
	// /docs/guides. Results from Markdown files add their section's anchor (#heading-id). "" gives no links.
	URL string `json:"url,omitempty"`
}

FolderInput is a folder of the app's files on the server.

FollowInput

type FollowInput struct {
	Bucket     string `json:"bucket"`
	Collection string `json:"collection"`
	// Fields are searched; the first is each record's title.
	Fields []string `json:"fields"`
	Filter string   `json:"filter,omitempty"` // a PocketBase filter, e.g. "published = true"
}

FollowInput is a collection.

ModelInput

type ModelInput struct {
	Model string `json:"model"`
}

ModelInput picks the app's embedding model.

PruneInput

type PruneInput struct {
	Bucket string   `json:"bucket"`
	Source string   `json:"source"`
	Keep   []string `json:"keep"` // every path the folder has now
}

PruneInput ends a folder upload.

PutInput

type PutInput struct {
	Bucket string `json:"bucket"`
	Source string `json:"source"` // the folder's name
	Path   string `json:"path"`   // the file's path inside the folder
	Text   string `json:"text"`
	// Replace names an existing source the folder replaces under its name (on its first file).
	Replace string `json:"replace,omitempty"`
}

PutInput is one file of a dropped folder.

RecordRef

type RecordRef struct {
	Collection string `json:"collection"`
	ID         string `json:"id"`
}

RecordRef names a record.

Ref

type Ref struct {
	Name string `json:"name"`
}

Ref names a bucket.

RemoveInput

type RemoveInput struct {
	Bucket  string   `json:"bucket"`
	Sources []string `json:"sources"`
}

RemoveInput names sources.

Removed

type Removed struct {
	Count int `json:"count"`
}

Removed says how many things a call affected.

Result

type Result struct {
	Bucket   string `json:"bucket"`
	Source   string `json:"source"`
	Document string `json:"document"`
	Text     string `json:"text"`
	// Heading is the section the chunk is in ("Install › macOS"), for Markdown, records and commits.
	Heading   string     `json:"heading,omitempty"`
	StartLine int        `json:"startLine"`
	EndLine   int        `json:"endLine"`
	Record    *RecordRef `json:"record,omitempty"`
	// URL links to where the passage is published, when its source knows: a web page's URL, or a server folder's URL
	// pattern with the section's anchor ("/docs/guides/install#macos").
	URL   string  `json:"url,omitempty"`
	Score float64 `json:"score"` // orders the results; higher is better
}

Result is one matching chunk and where it came from.

Results

type Results struct {
	Results []Result  `json:"results"`
	Model   string    `json:"model,omitempty"` // the model that embedded the query
	Usage   llm.Usage `json:"usage"`           // what embedding the query cost
}

Results are the best matches, best first (a Sample's are in no order, with no score).

SampleInput

type SampleInput struct {
	// Buckets are drawn from together; none draws from every bucket. Bucket is one more.
	Buckets []string `json:"buckets,omitempty"`
	Bucket  string   `json:"bucket,omitempty"`
	Count   int      `json:"count,omitempty"` // default 5, at most 50
	// Prefix keeps chunks from documents whose name starts with it.
	Prefix string `json:"prefix,omitempty"`
}

SampleInput is where to draw random chunks from.

type Search interface {
	// Status is the app's embedding model and how far embedding has got across every bucket.
	//
	//op: GET status scope=search:read
	Status(ctx context.Context, a extkit.Auth) (Status, error)
	// SetModel changes the app's embedding model ("provider/model" from llm.embed/v1's models; "" picks one again).
	// Every bucket is embedded again in the background; until a chunk is, keywords still find it.
	//
	//op: POST set-model
	SetModel(ctx context.Context, a extkit.Auth, in ModelInput) (Status, error)
	// Buckets lists the app's buckets with their counts.
	//
	//op: GET buckets scope=search:read
	Buckets(ctx context.Context, a extkit.Auth) (BucketList, error)
	// Bucket returns one bucket with its counts.
	//
	//op: GET bucket scope=search:read
	Bucket(ctx context.Context, a extkit.Auth, in Ref) (Bucket, error)
	// Ensure makes a bucket if it's missing and returns it. An existing bucket keeps its settings, except that an
	// empty title, description or owner is filled in. Apps call it at startup for the bucket they need.
	//
	//op: POST ensure
	Ensure(ctx context.Context, a extkit.Auth, in EnsureInput) (Bucket, error)
	// Update changes a bucket's title, description or limits (fields left out stay).
	//
	//op: POST update
	Update(ctx context.Context, a extkit.Auth, in UpdateInput) (Bucket, error)
	// Delete removes a bucket and everything in it.
	//
	//op: POST delete
	Delete(ctx context.Context, a extkit.Auth, in Ref) (Removed, error)
	// Sources lists a bucket's sources, by name.
	//
	//op: GET sources scope=search:read
	Sources(ctx context.Context, a extkit.Auth, in BucketRef) (SourceList, error)
	// Add puts a file or pasted text in a bucket as its own source (one document), replacing the source of that name.
	// The same text again costs nothing; changed text embeds only its new chunks. It returns at once; the document is
	// embedded in the background (its status says how far it got).
	//
	//op: POST add
	Add(ctx context.Context, a extkit.Auth, in AddInput) (Source, error)
	// Upload adds a file sent as the request body: ?bucket=<name>&name=<file name>[&replace=<source>]. A .zip is one
	// source with a document per text file inside it; anything else is a file source.
	//
	//op: POST upload
	Upload(ctx context.Context, a extkit.Auth, in extkit.RawIn) (Source, error)
	// Put adds one file to a folder source (made on the first one), the way the dashboard sends a dropped folder;
	// Prune ends it.
	//
	//op: POST put
	Put(ctx context.Context, a extkit.Auth, in PutInput) (Document, error)
	// Prune removes the documents of a folder source that aren't in Keep: the files the folder no longer has.
	//
	//op: POST prune
	Prune(ctx context.Context, a extkit.Auth, in PruneInput) (Source, error)
	// AddURL adds a web page or a Git repository as a source (named by its URL, replacing one of that name) and reads
	// it in the background; Every keeps it current.
	//
	//op: POST add-url
	AddURL(ctx context.Context, a extkit.Auth, in URLInput) (Source, error)
	// AddFolder adds a folder of the app's own files on the server (named by its path, replacing one of that name):
	// every text file in it, read in the background and read again every few minutes, so changed files are embedded
	// again and removed ones leave. With URL, each result from it links to the page that file is published at.
	//
	//op: POST add-folder
	AddFolder(ctx context.Context, a extkit.Auth, in FolderInput) (Source, error)
	// DetectURL says how AddURL would read a URL: as a Git repository when its server answers the Git protocol (any
	// host, with or without .git), otherwise as a web page.
	//
	//op: POST detect-url scope=search:read
	DetectURL(ctx context.Context, a extkit.Auth, in URLRef) (URLKind, error)
	// Follow adds one of the app's collections as a source (named by the collection): each record the filter keeps is
	// a document, kept in sync as records are saved and deleted.
	//
	//op: POST follow
	Follow(ctx context.Context, a extkit.Auth, in FollowInput) (Source, error)
	// Refresh reads a source again now: fetches a URL or repository, rereads a collection, resplits a file or zip.
	//
	//op: POST refresh
	Refresh(ctx context.Context, a extkit.Auth, in SourceRef) (Source, error)
	// Remove takes sources out of a bucket, with their documents.
	//
	//op: POST remove
	Remove(ctx context.Context, a extkit.Auth, in RemoveInput) (Removed, error)
	// Documents lists a bucket's documents (or one source's), by source and name.
	//
	//op: GET documents scope=search:read
	Documents(ctx context.Context, a extkit.Auth, in DocumentsInput) (DocumentList, error)
	// Search returns the chunks that best match a query across the buckets named, best first.
	//
	//op: POST search scope=search:read
	Search(ctx context.Context, a extkit.Auth, in SearchInput) (Results, error)
	// Sample returns chunks picked at random from the buckets named: material to draw from ("surprise me", a topic
	// nobody asked about), not matches. No query, no embedding, so it costs nothing. Like Search without a viewer, it
	// may return any chunk, a followed record's included.
	//
	//op: POST sample scope=search:read
	Sample(ctx context.Context, a extkit.Auth, in SampleInput) (Results, error)
}

Search keeps an app's search buckets and searches them.

SearchInput

type SearchInput struct {
	// Buckets are searched together; none searches every bucket. Bucket is one more, for a single-bucket search.
	Buckets []string `json:"buckets,omitempty"`
	Bucket  string   `json:"bucket,omitempty"`
	Query   string   `json:"query"`
	Limit   int      `json:"limit,omitempty"` // default 5, at most 50
	// Prefix keeps matches from documents whose name starts with it.
	Prefix string  `json:"prefix,omitempty"`
	Viewer *Viewer `json:"viewer,omitempty"`
}

SearchInput is a query.

Source

type Source struct {
	Bucket string `json:"bucket"`
	// Name identifies it in the bucket: the file, folder or zip name, the URL, or the collection.
	Name string `json:"name"`
	Kind string `json:"kind"`
	// URL, Every, Commits, Exclude: a page or repository source's settings.
	URL     string   `json:"url,omitempty"`
	Every   string   `json:"every,omitempty"`
	Commits int      `json:"commits,omitempty"`
	Exclude []string `json:"exclude,omitempty"`
	// Path, Include, PageURL: a server folder's settings (Exclude too).
	Path    string   `json:"path,omitempty"`
	Include []string `json:"include,omitempty"`
	PageURL string   `json:"pageURL,omitempty"`
	// Collection, Fields, Filter: a collection source's settings.
	Collection string   `json:"collection,omitempty"`
	Fields     []string `json:"fields,omitempty"`
	Filter     string   `json:"filter,omitempty"`
	// Hash is the sha256 of a file's or zip's content as uploaded, so the dashboard can tell an exact duplicate
	// under another name.
	Hash string `json:"hash,omitempty"`
	// Status is reading (fetching or splitting), ready or error; Error says why.
	Status       string     `json:"status"`
	Error        string     `json:"error,omitempty"`
	Documents    int        `json:"documents"`
	Chunks       int        `json:"chunks"`
	Embedded     int        `json:"embedded"` // chunks with the app's model's vectors
	Bytes        int64      `json:"bytes"`
	Pending      int        `json:"pending"` // documents waiting to be embedded
	CostMicroUSD int64      `json:"costMicroUSD"`
	Refreshed    *time.Time `json:"refreshed,omitempty"` // when it was last read
	Next         *time.Time `json:"next,omitempty"`      // when Every reads it next
	Created      time.Time  `json:"created"`
}

Source is one tracked unit in a bucket.

SourceList

type SourceList struct {
	Sources []Source `json:"sources"`
}

SourceList is a bucket's sources.

SourceRef

type SourceRef struct {
	Bucket string `json:"bucket"`
	Source string `json:"source"`
}

SourceRef names a source.

Status

type Status struct {
	// Model is the embedding model every bucket uses ("provider/model"); "" until one is picked (none available yet).
	Model string `json:"model"`
	// Chunks is how many chunks the app's buckets hold; Embedded how many have the model's vectors.
	Chunks   int `json:"chunks"`
	Embedded int `json:"embedded"`
	// Note says what's missing when nothing can be embedded (no embedding model among the app's providers).
	Note string `json:"note,omitempty"`
}

Status is the app's embedding model and its progress.

URLInput

type URLInput struct {
	Bucket string `json:"bucket"`
	URL    string `json:"url"` // http or https
	// Kind is page or git; "" asks the server (DetectURL).
	Kind  string `json:"kind,omitempty"`
	Every string `json:"every,omitempty"` // hour, day, week; "" reads it only when added or refreshed
	// Commits is how many recent commits of a repository become documents (subject, body, author, date, files; no
	// diffs): 0 is the default (300), -1 none.
	Commits int `json:"commits,omitempty"`
	// Exclude skips a repository's files whose path, or any folder in it, matches one of these patterns ("docs/old",
	// "*.min.js"), beside what's always skipped (binaries, .git, node_modules, vendor, lockfiles).
	Exclude []string `json:"exclude,omitempty"`
}

URLInput is a web page or a Git repository.

URLKind

type URLKind struct {
	Kind string `json:"kind"`
}

URLKind is how a URL would be read: git or page.

URLRef

type URLRef struct {
	URL string `json:"url"`
}

URLRef is a URL.

UpdateInput

type UpdateInput struct {
	Name         string  `json:"name"`
	Title        *string `json:"title,omitempty"`
	Description  *string `json:"description,omitempty"`
	MaxDocuments *int    `json:"maxDocuments,omitempty"`
	MaxBytes     *int64  `json:"maxBytes,omitempty"`
}

UpdateInput changes a bucket.

Viewer

type Viewer struct {
	// Collection and ID are the signed-in auth record; both empty is a guest (signed out).
	Collection string `json:"collection,omitempty"`
	ID         string `json:"id,omitempty"`
}

Viewer is who a search is for. Matches from records they can't view (the collection's view rule, as PocketBase checks it) are left out; documents that aren't records are for everyone. A search without one sees everything.