Search, inference, and plugin architecture
Karakeep uses shared service contracts to keep asset storage, search, vector retrieval, queues, rate limits, and model calls independent from their providers. The web app and workers request capabilities through these contracts. Startup loads configured providers, then shared services use the selected client without depending on a specific local or hosted system.
Plugin selection
Provider registration
The plugin manager is the common registry for asset-store, search, queue, rate-limit, and vector-store providers. A provider declares one capability and exposes its client through that capability. Loading a provider module registers it, so application startup only needs to load the required modules before services request clients (packages/…/plugins.ts• L9-31, packages/…/package.json• L7-17). Inference uses a shared factory instead of this registry.
Providers remain in load order. A duplicate name for one capability is ignored. When different providers serve the same capability, the last registered provider is selected. This lets a configured service replace a local default, but it makes module load order part of service selection (packages/…/plugins.ts• L55-81, packages/…/plugins.ts• L24-39).
| Capability | Concrete providers | Selection result |
|---|---|---|
| Asset store | Filesystem and S3 | Filesystem is the baseline. S3 replaces it when its endpoint and required settings are configured. |
| Queue | Liteque and Restate | Restate replaces Liteque when Restate is configured. |
| Search | Meilisearch | Available when a Meilisearch address is configured. |
| Vector store | Meilisearch Vector | Uses the vector-specific address when set. Otherwise it can share the main Meilisearch service. |
| Rate limit | In-memory and Redis | Redis replaces the in-memory provider when a Redis URL is configured. |
The @karakeep/plugins package exposes provider entry points and separate asset-store implementation entry points. Shared server startup uses the provider entries. Focused tools and tests can create an asset store through its implementation entry point (packages/…/package.json• L7-17).
References: packages/…/plugins.ts• L9-31 packages/…/plugins.ts• L55-109 packages/…/plugins.ts• L16-39 packages/…/package.json• L7-17 packages/…/config.ts• L215-227 packages/…/config.ts• L530-553
Client access
Shared accessors turn the registry into service boundaries. Asset storage and queues require a client because their core operations cannot run without one. Search, vector retrieval, and rate limiting may return no client, which lets a deployment run without those optional capabilities (packages/…/assetdb.ts• L22-29, packages/…/queueing.ts• L94-112, packages/…/search.ts• L71-83, packages/…/vectorStore.ts• L80-88, packages/…/ratelimiting.ts• L13-40).
The server loads plugins once and shares the result within the process. Concurrent load requests wait for the same load operation. Queue objects are created only when needed, so importing queue definitions does not connect to a backend until a service uses a queue (packages/…/plugins.ts• L3-45, packages/…/queues.ts• L19-67).
References: packages/…/assetdb.ts• L22-29 packages/…/queueing.ts• L74-112 packages/…/search.ts• L71-83 packages/…/vectorStore.ts• L52-88 packages/…/ratelimiting.ts• L13-40 packages/…/plugins.ts• L3-45 packages/…/queues.ts• L19-67
Asset storage
Asset-store contract
The asset-store contract gives the application one way to save, read, stream, inspect, list, and delete user assets. It includes metadata and byte-range reads, so callers can serve large content without knowing where the bytes are stored (packages/…/assetdb.ts• L52-108).
The shared server boundary checks quota before it saves an asset. Crawling, preprocessing, parsing, and tagging use this boundary for content they create or read. The boundary then forwards the operation to the selected store (packages/…/assetdb.ts• L22-159, apps/…/assetStorage.ts• L81-212, apps/…/assetPreprocessingWorker.ts• L240-414).
References: packages/…/assetdb.ts• L52-108 packages/…/assetdb.ts• L22-159 apps/…/assetStorage.ts• L81-212 apps/…/assetPreprocessingWorker.ts• L240-414
Asset-store backends
The filesystem backend keeps each user's assets under a local root. It stores the asset bytes with a validated metadata record and supports full reads, range reads, streams, size checks, enumeration, and deletion. The S3 backend presents the same contract through an object bucket, so the rest of the system does not change when storage moves (packages/…/index.ts• L11-205, packages/…/index.ts• L17-275).
The filesystem provider is the baseline. The S3 provider loads after it and becomes selected only when its endpoint, bucket, and credentials are configured (packages/…/plugins.ts• L24-31, packages/…/index.ts• L6-24, packages/…/index.ts• L43-67, packages/…/config.ts• L215-221, packages/…/config.ts• L530-541).
For backend-specific storage behavior and deployment choices, see Asset storage backends.
References: packages/…/index.ts• L6-24 packages/…/index.ts• L11-205 packages/…/index.ts• L15-67 packages/…/index.ts• L17-275 packages/…/plugins.ts• L24-31 packages/…/config.ts• L215-221 packages/…/config.ts• L530-541
Queue abstraction
Queue contract
The queue contract gives application jobs one lifecycle across local and distributed execution. A queue accepts typed payloads and supports idempotency, priority, delay, and grouping. A runner consumes jobs with a concurrency limit and timeout, then reports completion or failure (packages/…/queueing.ts• L20-104).
The shared server defines queues for asynchronous work such as crawling, inference, embeddings, indexing, asset processing, webhooks, rules, feeds, video, backups, and maintenance. Queue names and payload shapes form the contract between producers and workers (packages/…/queues.ts• L80-336).
This diagram shows how an application action reaches a worker through the selected queue backend.
flowchart LR
A[Web request or worker event] --> B[Typed shared queue]
B --> C[Selected QueueClient]
C --> D[Queue backend]
D --> E[Worker runner]
E --> F[Domain action]
References: packages/…/queueing.ts• L20-104 packages/…/queues.ts• L80-190 apps/…/index.ts• L43-92
Queue backends
Liteque provides local queue execution through a SQLite-backed queue. It is the baseline for a single process or simple deployment. Restate provides service-based execution through its ingress, dispatcher, and runner services. It is selected when its deployment setting is present (packages/…/index.ts• L65-160, packages/…/index.ts• L129-219, packages/…/env.ts• L10-25).
Both backends preserve the shared queue shape. Their main difference is where execution runs: Liteque polls in the worker process, while Restate sends work through its service model. Each adapter maps its backend's retry and status behavior to the shared runner model (packages/…/index.ts• L97-142, packages/…/index.ts• L38-69, packages/…/index.ts• L97-126).
For backend-specific lifecycle and deployment behavior, see Queue execution backends.
References: packages/…/index.ts• L65-160 packages/…/index.ts• L129-219 packages/…/env.ts• L10-25
Worker lifecycle
The worker process loads plugins before it prepares queues. It builds only the enabled workers, starts the queue service, and runs workers until shutdown (apps/…/index.ts• L94-176). Each worker creates a runner from a shared queue and supplies its domain action with concurrency and timeout settings (apps/…/searchWorker.ts• L23-60, apps/…/inferenceWorker.ts• L44-80).
Jobs can request a delayed retry without consuming a normal retry attempt. The crawler uses this path when a target domain is rate limited. The selected queue adapter converts the shared signal into backend-specific delayed retry behavior (packages/…/queueing.ts• L5-18, apps/…/crawlerWorker.ts• L229-255).
References: apps/…/index.ts• L108-176 apps/…/searchWorker.ts• L23-60 apps/…/inferenceWorker.ts• L44-80 packages/…/queueing.ts• L5-18 apps/…/crawlerWorker.ts• L223-255
Search and vector retrieval
Search contract
The search contract turns bookmark data into searchable documents and returns bookmark IDs with scores. It supports text queries, user or ID filters, paging, and creation-time sorting. The same boundary adds, deletes, and clears indexed documents (packages/…/search.ts• L5-79).
The search worker builds one document from the bookmark's link, text, assets, note, tags, and summary. It sends that document to the selected search client. A delete job removes the bookmark ID from the index (apps/…/searchWorker.ts• L63-175).
Structured search terms use a shared query language beside the provider search path. The parser separates free text from typed matchers and supports nested and and or groups with positive or negative terms. The matcher schema is then resolved by the local search service for user-scoped bookmark, tag, list, feed, date, type, and content-presence filters (packages/…/searchQueryParser.ts• L121-187, packages/…/searchQueryParser.ts• L191-331, packages/…/search.ts• L107-161).
Unknown terms remain free text and unfinished expressions remain partial. This lets a user continue typing without turning incomplete input into a filter. The local search service intersects and results and unions or results before combining them with provider-backed search (packages/…/searchQueryParser.ts• L435-472, packages/…/search.ts• L41-92, packages/…/search.ts• L475-500).
Meilisearch is the concrete text-search integration. It manages the bookmark index and maps the shared query result to the provider's result shape (packages/…/index.ts• L31-119, packages/…/index.ts• L122-222).
Vector-store contract
The vector-store contract keeps one numeric embedding for each bookmark and supports nearest-vector and similar-bookmark search. It also supports filters, score thresholds, deletion, index clearing, and health checks (packages/…/vectorStore.ts• L5-84).
The embeddings worker separates model work from index work. It generates an embedding, sends the vector with the tagging job, and sends a separate index job to persist the vector. This prevents a slow or failed index update from repeating tagging (apps/…/embeddingsWorker.ts• L346-391, apps/…/embeddingsWorker.ts• L394-437).
Meilisearch Vector is the concrete vector integration. It stores user vectors in the bookmark vector index and uses the configured embedding dimension when it prepares that index (packages/…/index.ts• L42-145, packages/…/index.ts• L148-287).
For user-facing search modes and the relationship between text search and vector retrieval, see Search and vector retrieval.
References: packages/…/search.ts• L5-83 apps/…/searchWorker.ts• L63-175 packages/…/searchQueryParser.ts• L121-187 packages/…/searchQueryParser.ts• L191-331 packages/…/searchQueryParser.ts• L435-472 packages/…/search.ts• L107-161 packages/…/search.ts• L41-92 packages/…/search.ts• L475-500 packages/…/index.ts• L31-222 packages/…/vectorStore.ts• L5-88 apps/…/embeddingsWorker.ts• L346-437 packages/…/index.ts• L42-287
Search service use
The bookmark router uses the shared search client for full-text search. Semantic search needs both an embedding client and a vector-store client. Hybrid search can fall back to full-text search when semantic search fails. An explicit semantic request reports the missing or failed semantic service (packages/…/bookmarks.ts• L950-1054).
The bookmark search path combines provider-backed text or vector retrieval with local matcher resolution. The parser and matcher resolver therefore form a joint contract: supported terms must produce local filters, while free text must remain available to the selected provider (packages/…/searchQueryParser.ts• L435-472, packages/…/search.ts• L94-102, packages/…/search.ts• L475-500).
Admin actions use the same clients to clear indexes and enqueue reindex or embedding work. The admin status view checks search and vector services separately, so one disconnected service does not hide the state of the other (packages/…/admin.ts• L300-344, packages/…/admin.ts• L650-702).
References: packages/…/bookmarks.ts• L950-1054 packages/…/searchQueryParser.ts• L435-472 packages/…/search.ts• L94-102 packages/…/search.ts• L475-500 packages/…/admin.ts• L300-344 packages/…/admin.ts• L650-702
Rate-limit abstraction
Rate-limit contract
The rate-limit contract answers whether a named key may make a request during a time window. It also supports reset and clear operations. A blocked result includes the wait time (packages/…/ratelimiting.ts• L3-35).
The in-memory provider keeps counters in the current process. Redis keeps the same decision in shared state and uses an atomic operation for concurrent requests. Redis errors fail open, so a rate-limit outage does not block all traffic (packages/…/index.ts• L13-75, packages/…/index.ts• L11-34, packages/…/index.ts• L16-103).
The Redis provider registers only when a Redis URL is configured. Its client is created on first use, so plugin loading does not open a Redis connection by itself (packages/…/index.ts• L11-33).
References: packages/…/ratelimiting.ts• L3-40 packages/…/index.ts• L13-85 packages/…/index.ts• L1-34 packages/…/index.ts• L16-103
Rate-limit service use
HTTP and tRPC middleware build keys from the client IP, the signed-in user when present, and the protected route. A blocked request becomes HTTP 429 or a tRPC too-many-requests error. If rate limiting is disabled or no provider exists, the request continues (packages/…/rateLimit.ts• L9-40, packages/…/rateLimit.ts• L12-50).
The crawler uses the same abstraction for per-domain limits. A blocked domain becomes a delayed queue retry with jitter. Authentication limits repeated credential attempts. Rate-limited event logging uses the client as a best-effort de-duplication gate and does not change request handling (apps/…/crawlerWorker.ts• L223-255, apps/…/auth.ts• L124-163, packages/…/rateLimitedEvent.ts• L10-39).
References: packages/…/rateLimit.ts• L9-40 packages/…/rateLimit.ts• L12-50 apps/…/crawlerWorker.ts• L223-255 apps/…/auth.ts• L124-163 packages/…/rateLimitedEvent.ts• L10-39
Inference abstraction
Model client contract
The inference client provides text generation, image-aware generation, and text embedding through one model boundary. Generation can return plain text or follow a requested schema. Embedding responses include vectors and provider token counts (packages/…/inference.ts• L11-20, packages/…/inference.ts• L116-141).
The inference factory chooses OpenAI when an OpenAI key exists. It chooses Ollama when an Ollama endpoint exists and returns no client when neither is configured. The embedding factory can use a separate OpenAI embedding endpoint or fall back to the selected inference client (packages/…/inference.ts• L208-247).
Configuration also sets the model boundary's operating rules. The default OpenAI setup enables completion-token handling and embedding auto-indexing. Ollama and custom OpenAI endpoints leave those behaviors disabled unless an operator enables them. Configuration exposes text and image models, output mode, context and output limits, embedding model and dimension, and worker timeouts (packages/…/config.ts• L71-109, packages/…/config.ts• L370-432). The current default text model is gpt-6-luna, while deployments can select another model or endpoint through the same configuration boundary (packages/…/config.ts• L81-107, packages/…/config.ts• L383-405).
Both concrete clients normalize provider responses into the shared result shape. They enforce the configured embedding dimension, which keeps vectors compatible with the vector store (packages/…/inference.ts• L32-41, packages/…/inference.ts• L250-275, packages/…/inference.ts• L277-409, packages/…/inference.ts• L422-565).
References: packages/…/inference.ts• L11-20 packages/…/inference.ts• L116-141 packages/…/inference.ts• L208-247 packages/…/inference.ts• L250-275 packages/…/inference.ts• L277-409 packages/…/inference.ts• L422-565 packages/…/config.ts• L71-109 packages/…/config.ts• L370-432
Inference service use
The inference worker consumes queued summarize and tag jobs. It selects a model client at run time and updates bookmark status after completion or after the final failed attempt (apps/…/inferenceWorker.ts• L21-123). Direct bookmark summarization uses the same factory, so synchronous API work and queued work follow the same provider choice (packages/…/bookmarks.ts• L1480-1524).
Embedding jobs use the embedding factory and vector-store client together. If either service is absent, the worker skips the unavailable part and can still send tagging work through its fallback path (apps/…/embeddingsWorker.ts• L357-437). These jobs are part of the wider content flow described in Content ingestion and enrichment jobs.
References: apps/…/inferenceWorker.ts• L21-123 packages/…/bookmarks.ts• L1480-1524 apps/…/embeddingsWorker.ts• L357-437
Shared service boundaries
Startup paths
The web process loads all plugins during node instrumentation. The worker process loads them before queue preparation and worker construction. Both processes therefore use the same provider selection rules, while only the worker process runs queue consumers (apps/…/instrumentation.node.ts• L1-9, apps/…/index.ts• L108-126).
The path from configuration to domain behavior is:
sequenceDiagram
participant Start as Web or worker startup
participant Loader as Plugin loader
participant Registry as Plugin manager
participant Service as Shared service
participant Provider as Selected provider
Start->>Loader: Load configured modules
Loader->>Registry: Register providers in order
Service->>Registry: Request a client
Registry->>Provider: Resolve the last provider
Provider-->>Service: Return client or no client
Service->>Provider: Perform the domain operation
References: apps/…/instrumentation.node.ts• L1-9 apps/…/index.ts• L108-126 packages/…/plugins.ts• L16-39 packages/…/plugins.ts• L65-89
Capability fallbacks
Optional capability boundaries make feature availability explicit. Full-text search needs a search client. Semantic search needs both model embeddings and a vector store. Rate-limited paths continue when rate limiting is disabled or unavailable. Inference and embedding jobs also exit cleanly when no model provider is configured (packages/…/bookmarks.ts• L988-1054, packages/…/rateLimit.ts• L21-36, apps/…/inferenceWorker.ts• L83-99, apps/…/embeddingsWorker.ts• L357-367).
The client advertises semantic search only when the semantic-search flag is on, embedding auto-indexing is on, and an embedding provider is configured. This keeps visible feature state aligned with the settings that can produce searchable vectors. The public client-config schema validates this feature state before it reaches client code (packages/…/config.ts• L414-432, packages/…/config.ts• L664-678, packages/…/config.ts• L3-50).
Asset operations are different from optional search and model features. The shared asset boundary requires a selected asset store and reports an error when none is registered. Missing durable storage is therefore visible instead of silently losing user content (packages/…/assetdb.ts• L22-29).
These choices keep optional integrations from changing the core bookmark flow. A provider can still be configured but disconnected when its lazy connection fails. Admin status checks expose that state for search and vector retrieval (packages/…/admin.ts• L663-702).
References: packages/…/bookmarks.ts• L988-1054 packages/…/rateLimit.ts• L21-36 packages/…/assetdb.ts• L22-29 apps/…/inferenceWorker.ts• L83-99 apps/…/embeddingsWorker.ts• L357-367 packages/…/admin.ts• L663-702 packages/…/config.ts• L414-432 packages/…/config.ts• L664-678 packages/…/config.ts• L3-50
Change checklist
When these files or sections are changed, remember to consider these:
- Keep provider load order aligned with the override rule. A newly loaded provider can silently replace an existing provider of the same type.
- Keep asset-store metadata and byte-range behavior aligned across the shared contract and every backend. Readers can depend on both when serving stored content.
- Keep queue names, payload schemas, and worker runners aligned. A payload change affects every producer and every selected queue backend.
- Keep embedding dimensions aligned across model configuration, vector-index setup, and stored vectors. A mismatch stops embedding work before indexing.
- Keep search and vector filter fields aligned with the fields configured in their indexes. A client can be present while filtered queries still fail.
- Keep query parser terms, the recursive matcher schema, and the local matcher resolver aligned. A term can parse successfully but return incomplete results if only one layer knows it.
- Keep optional-client behavior aligned between API routes and workers. A missing client must produce the intended fallback instead of an unhandled null result.
- Keep delayed retry behavior supported by every queue backend. Domain rate limits depend on the shared retry-after signal.
- Keep inference and embedding defaults aligned with provider type. The default OpenAI path enables behaviors that custom endpoints and Ollama do not enable automatically.
- Keep the public client-config schema aligned with the server fields that expose feature readiness. A server-side setting can be correct while client feature state is rejected or incomplete.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| No asset-store provider is registered | Asset saves and reads fail through the shared server boundary. | Load the filesystem provider or configure S3 before serving asset operations. |
| S3 is selected without its bucket or credentials | Plugin loading fails instead of starting with a usable asset store. | Provide the required S3 settings when selecting S3. |
| No queue provider is registered | Queue access fails and workers cannot start their runners. | Load the plugin set before queue preparation. |
| Two providers register for one capability | The last provider handles later client requests. | Review plugin import order when adding or changing a provider. |
| Meilisearch is not configured or cannot connect | Full-text indexing or search is unavailable. Semantic search can fall back to full text only in hybrid mode. | Check admin search status and configure the search service before requiring search. |
| A query term is parsed but has no matching local resolver | The request can appear valid while the intended filter is absent from results. | Update the parser, matcher schema, and matcher resolver as one contract. |
| Embedding length differs from the configured dimension | The embedding call fails and the vector cannot be stored or searched. | Use one embedding dimension across model and vector-store settings. |
| Redis rate-limit operations fail | Requests are allowed without the intended shared limit. | Monitor Redis and treat rate limiting as fail-open protection, not access control. |
| A domain reaches its crawler limit | The crawl job waits and retries instead of overloading the domain. | Preserve delayed-retry support in every queue adapter. |
| No inference or embedding provider is configured | Summaries, tags, or embeddings are skipped or rejected by the calling path. | Check provider configuration before enabling dependent features. |
| Semantic search is enabled without embedding auto-indexing | The client does not advertise semantic search and new vectors are not auto-indexed. | Enable auto-indexing and configure an embedding provider with the semantic-search flag. |
| Server client-config fields and their shared schema diverge | Client startup or feature checks reject valid server state or miss a capability. | Update clientConfig and zClientConfigSchema together. |
Key files
| File | Why to read it |
|---|---|
| packages/…/plugins.ts | Defines provider registration, lookup, and last-provider-wins selection. |
| packages/…/package.json | Shows the public provider and asset-store implementation entry points. |
| packages/…/config.ts | Defines provider settings, model defaults, embedding readiness, and client-visible semantic-search state. |
| packages/…/config.ts | Validates the shape of configuration that the server exposes to client code. |
| packages/…/assetdb.ts | Defines the asset metadata and storage contract. |
| packages/…/assetdb.ts | Shows how shared asset operations resolve the selected store and apply quota checks. |
| packages/…/index.ts | Shows default filesystem provider registration. |
| packages/…/index.ts | Shows filesystem asset persistence and range-read behavior. |
| packages/…/index.ts | Shows S3 selection and required configuration checks. |
| packages/…/queueing.ts | Defines the queue and runner contract shared by all queue backends. |
| packages/…/search.ts | Defines bookmark search documents and text-search behavior. |
| packages/…/searchQueryParser.ts | Separates free text from structured search terms and preserves partial input. |
| packages/…/search.ts | Defines the recursive matcher contract used by structured search. |
| packages/…/search.ts | Resolves structured matchers into user-scoped bookmark IDs. |
| packages/…/vectorStore.ts | Defines vector storage, nearest search, similar search, and health behavior. |
| packages/…/ratelimiting.ts | Defines the rate-limit decision contract. |
| packages/…/inference.ts | Selects OpenAI or Ollama and normalizes generation and embedding calls. |
| packages/…/plugins.ts | Loads provider modules and establishes their order. |
| packages/…/queues.ts | Defines application queues and typed job contracts. |
| apps/…/index.ts | Shows worker startup, queue preparation, and worker selection. |
| packages/…/index.ts | Shows the local queue integration. |
| packages/…/index.ts | Shows the distributed queue integration. |
| packages/…/index.ts | Shows the concrete full-text search integration. |
| packages/…/index.ts | Shows the concrete vector-store integration. |
| packages/…/index.ts | Shows the process-local rate-limit integration. |
| packages/…/index.ts | Shows Redis provider registration and lazy construction. |
| apps/…/embeddingsWorker.ts | Shows the split between embedding generation, tagging, and vector indexing. |
| packages/…/bookmarks.ts | Shows how API search and summarization select shared clients. |