pkg/kiwi package runs a full KiwiFS server, with its REST API, web UI, search, and versioning, inside your Go process. Use it to ship a knowledge base as part of your own binary, or to mount KiwiFS next to your application’s routes.
Install
Terminal
Quick start
main.go
kiwi.New creates the directory if needed and initializes a git repository there when versioning is git. It also watches the directory, so files you edit on disk are committed and indexed.
kiwi.New doesn’t read .kiwi/config.toml. The embedded server uses the options you pass and the defaults below. Features configured only in config.toml, such as vector search or backup sync, aren’t available when embedding.Options
WithSearch(engine string)
WithSearch(engine string)
Search engine:
"sqlite" (default) for full-text search with BM25 ranking, or "grep" for index-free substring matching.WithVersioning(strategy string)
WithVersioning(strategy string)
Versioning strategy:
"git" (default), "cow" for copy-on-write snapshots, or "none".WithAuth(authType, apiKey string)
WithAuth(authType, apiKey string)
Authentication. Use
"apikey" with a key to require Authorization: Bearer <key> on API requests. The default is "none".WithCORSOrigins(origins ...string)
WithCORSOrigins(origins ...string)
Origins allowed to call the API from a browser, such as
"https://app.example.com".Server methods
Handler() http.Handler
Handler() http.Handler
Returns the HTTP handler for the REST API and web UI. Use it to serve KiwiFS from your own
http.Server or router. The embedded server doesn’t expose the /mcp endpoint that kiwifs serve adds.Pipeline() *pipeline.Pipeline
Pipeline() *pipeline.Pipeline
Returns the write pipeline for reading and writing pages from Go. See Read and write pages from Go.
ListenAndServe(addr string) error
ListenAndServe(addr string) error
Serves
Handler() on addr with http.ListenAndServe. It blocks until the listener fails.Shutdown(ctx context.Context) error
Shutdown(ctx context.Context) error
Stops KiwiFS’s background schedulers. It doesn’t stop a listener started with
ListenAndServe. For graceful shutdown, run your own http.Server as shown below.Close() error
Close() error
Stops the file watcher and releases search indexes, vector stores, and git resources. Call it once before your program exits.
Mount next to your own routes
The web UI loads its assets from absolute paths, so mount KiwiFS at the root and put your own routes on paths it doesn’t use. KiwiFS serves its API under/api/kiwi/.
main.go
http.StripPrefix. The web UI won’t work under a prefix.
Read and write pages from Go
Pipeline() gives you the same write path the REST API uses. Every write is committed to git, indexed for search, and broadcast to connected clients.
Graceful shutdown
ServeHandler() from an http.Server you control, shut that down first, then close KiwiFS.
main.go
Close() before exiting. Skipping it can leave pending commits unflushed and search indexes in an inconsistent state, which kiwifs reindex can repair.
Related
REST API
The endpoints
Handler() serves.Files as truth
Why every write goes through the pipeline.