Introducing a new way to review your PRs.

Read the announcement

karakeep-app / karakeep

A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search

View on GitHub

21 documents · Updated Nov 23, 2026

docs / search-and-vector-retrieval

Search and vector retrieval

Search and vector retrieval help users find saved bookmarks by words, filters, and meaning. The system turns one search request into a scoped set of bookmark IDs, uses full-text or vector ranking to order them, and then returns the normal bookmark records to the dashboard and API.

Content discovery

Search purpose

Search gives content discovery one shared path across links, notes, text bookmarks, and media. It keeps user scope and bookmark filters separate from ranking so that relevance can improve without weakening access checks.

The search result is a list of bookmark IDs and ranking data. The bookmark service loads the full records after retrieval, which keeps the search index focused on discovery and keeps the database as the source of bookmark details.

References: packages/…/bookmarks.ts• L933-975 packages/…/bookmarks.ts• L1131-1169 packages/…/search.ts• L5-25

Query model

The shared query parser in packages/…/searchQueryParser.ts separates free text from structured matchers. Free text goes to the ranking service. Matchers describe conditions such as tags, lists, dates, bookmark type, source, archive state, and link health.

Spaces act as an AND condition. The query language also supports explicit and and or, parentheses, and - or ! to invert a condition. Invalid or unfinished input remains usable as text while the user types. Structured matchers resolve to bookmark IDs through the database, then become provider filters.

References: packages/…/searchQueryParser.ts• L39-60 packages/…/searchQueryParser.ts• L121-367 packages/…/searchQueryParser.ts• L414-451 packages/…/search.ts• L5-19 packages/…/search.ts• L93-99 packages/…/search.ts• L422-447

Retrieval paths

Full-text retrieval

Full-text retrieval finds words in the searchable bookmark profile. That profile can include titles, URLs, link details, descriptions, saved content, notes, summaries, tags, and publishing details. The search index returns IDs, ranking scores, result counts, and processing time.

Full-text mode supports relevance ranking and date sorting. It is also the safe fallback when a hybrid query cannot use its vector path.

References: packages/…/search.ts• L5-25 packages/…/search.ts• L27-79 packages/…/index.ts• L85-104 packages/…/bookmarks.ts• L988-1025

Vector retrieval

Vector retrieval finds bookmarks with content that is close in meaning to the query. An embedding provider converts the query text into a numeric vector. The vector store compares that vector with stored bookmark vectors and returns ranked IDs.

The vector path applies the same user and bookmark filters as full-text search. It needs both an embedding provider and a vector-store provider. A query that contains only filters has no text to convert into a vector, so it uses full-text retrieval instead.

References: packages/…/bookmarks.ts• L1032-1095 packages/…/inference.ts• L126-128 packages/…/vectorStore.ts• L26-49 packages/…/index.ts• L79-121

Hybrid retrieval

Hybrid retrieval combines word matching with meaning matching. It requests a fixed candidate window from both sources, then uses reciprocal-rank fusion to raise bookmarks that rank well in both lists. Reciprocal-rank fusion combines positions rather than raw scores because the two score types do not share a scale.

If the full-text source fails, the request fails. If only the semantic source fails, hybrid mode records the degradation and returns full-text results. This gives users useful discovery when vector services are unavailable without hiding a full-text outage.

The following flow shows how a query moves from parsing to filtered retrieval and bookmark loading.

flowchart LR
    A[Search request] --> B[Parse text and matchers]
    B --> C[Resolve matchers to bookmark IDs]
    C --> D{Search mode}
    D -->|Full text| E[Search index]
    D -->|Semantic| F[Embed query]
    F --> G[Vector store]
    D -->|Hybrid| E
    D -->|Hybrid| F
    E --> H[Ranked IDs]
    G --> H
    H --> I[Load bookmark records]
    I --> J[Paginated response]

References: packages/…/bookmarks.ts• L1016-1127 packages/…/searchRanking.ts• L6-47

Index lifecycle

Search index

The search index is a discovery view of bookmark data. A search indexing worker builds or removes one document when a bookmark changes, so search can use content fields without joining every bookmark relation during each query.

The Meilisearch-backed provider creates the bookmarks index when needed. It exposes only the fields needed by the shared contract and keeps user ID and bookmark ID available for scoped filtering. Index updates may be batched for normal work and sent directly on retries.

References: apps/…/searchWorker.ts• L63-126 apps/…/searchWorker.ts• L128-175 packages/…/index.ts• L31-119 packages/…/index.ts• L162-221

Vector index

The vector index is a meaning-based discovery view. An embeddings worker prepares a compact representation of a bookmark, asks the embedding provider for a vector, and sends that vector to the vector store. Delete and re-index jobs keep the vector view aligned with bookmark life-cycle changes.

The Meilisearch-backed vector provider stores vectors in a separate bookmarks_vectors index. It uses a user-provided embedder because the application creates the vectors. The configured vector size must match the embedding provider and the vector index.

References: apps/…/embeddingsWorker.ts• L256-344 apps/…/embeddingsWorker.ts• L348-391 apps/…/embeddingsWorker.ts• L457-498 packages/…/index.ts• L148-287

Asynchronous indexing

Index maintenance runs outside the search request through search and embedding queues. This keeps bookmark writes and user actions responsive, but it means a recent change can be visible in the database before it is visible in one or both discovery views.

The embedding flow separates vector creation from vector persistence. It can pass the new vector to downstream tagging while a separate job handles storage, so a storage retry does not repeat the tagging action.

References: packages/…/queues.ts• L145-183 apps/…/searchWorker.ts• L23-60 apps/…/embeddingsWorker.ts• L394-498

Provider contracts

Search index contract

The shared SearchIndexClient contract defines the boundary between search behavior and a search provider. It covers document add and delete, ranked search, and index clearing. Search requests carry a query, ANDed filters, paging, and an optional date sort; responses carry IDs, optional scores, a total, and timing data.

The plugin manager supplies the active provider. The current provider uses Meilisearch, but callers depend on the shared contract rather than on that service. Search is available to the application only when a provider is registered and can connect.

References: packages/…/search.ts• L27-83 packages/…/plugins.ts• L9-31 packages/…/plugins.ts• L61-89 packages/…/plugins.ts• L24-35

Vector-store contract

The shared VectorStoreClient contract defines how the application stores and searches bookmark vectors. It supports add, delete, vector search, similar-bookmark search, index clearing, and health checks. Vector filters are limited to user ID and bookmark ID so every provider can enforce the same scope rules.

The contract keeps embedding creation separate from vector storage. An embedding provider only creates numeric vectors. The vector store owns ranking and similar-item lookup for those vectors.

References: packages/…/vectorStore.ts• L5-24 packages/…/vectorStore.ts• L26-88 packages/…/inference.ts• L221-247 packages/…/plugins.ts• L29-30

Search modes

The search interface offers full-text, semantic, and hybrid modes. Full-text is the default and supports date sorting. Semantic and hybrid modes require relevance sorting because their results are ordered by meaning or by fused rank.

The web client keeps the query and mode in the search URL. It hides semantic behavior when the server does not advertise it, and it forces filter-only queries to full-text retrieval because those queries have no text to embed. The API accepts the same three modes through the bookmark search request.

ModeMain signalService needsSorting
Full-textWord matchesSearch providerRelevance or date
SemanticMeaning similaritySearch provider, embedding provider, and vector storeRelevance
HybridWord matches plus meaning similarityBoth retrieval pathsRelevance

References: apps/…/bookmark-search.ts• L13-70 apps/…/bookmark-search.ts• L136-175 packages/…/bookmarks.ts• L353-368 packages/…/bookmarks.ts• L953-961 packages/…/bookmarks.ts• L1064-1069

Access and paging

Every search is scoped to the signed-in user. Qualifier results add an ID filter before the provider search, and the provider also receives the user ID filter. The service then loads only the returned IDs and preserves the selected relevance or date order.

Paging uses an offset cursor. Full-text retrieval can page at the provider. Semantic and hybrid retrieval fetch a ranked window, slice that window for the requested page, and report whether more candidates remain.

References: packages/…/bookmarks.ts• L964-976 packages/…/bookmarks.ts• L983-1014 packages/…/bookmarks.ts• L1098-1125 packages/…/bookmarks.ts• L1138-1169

Change checklist

When these files or sections are changed, remember to consider these:

  • A new query qualifier must stay aligned across token parsing, the recursive matcher schema, database ID resolution, and provider filter handling.
  • A searchable bookmark field must be updated in both the search document contract and the worker that builds index documents.
  • A change to embedding dimensions or the embedding model must stay aligned with provider validation, vector-index embedder settings, and existing vectors. Plan a full re-index when old vectors are no longer compatible.
  • A new search mode must stay aligned across the request schema, API types, web URL state, server capability checks, sort rules, and fallback behavior.
  • Search and vector index changes must preserve the user ID and bookmark ID filter contract. Losing either filter can expose cross-user candidates or prevent qualifier results from narrowing retrieval.

Important failure modes

TriggerConsequenceGuard
No search provider is configuredFull-text search cannot serve the requestRegister a search provider before exposing the search page and endpoint
Semantic search has no embedding provider, vector store, or query textAn explicit semantic request is rejected; hybrid mode falls back to full-textCheck semantic prerequisites before embedding and keep the hybrid fallback
Embedding output has the wrong vector sizeEmbedding generation or vector indexing fails, so semantic results become stale or unavailableValidate dimensions and keep them equal to the configured vector-index dimensions
A search or embedding indexing job is delayed or permanently failsDatabase changes are not yet reflected in discovery resultsUse queue retries and monitor indexing and embedding status
Full-text retrieval fails during hybrid searchThe hybrid request fails instead of returning only semantic resultsTreat the full-text path as required for hybrid ranking
Vector retrieval fails during hybrid searchHybrid results degrade to full-text resultsRecord degradation and keep full-text retrieval available

Key files

FileWhy to read it
packages/…/bookmarks.tsShows the end-to-end search request, mode selection, filtering, fallback, paging, and bookmark loading flow.
packages/…/searchQueryParser.tsDefines how user search text becomes free text and structured conditions.
packages/…/search.tsShows how structured conditions become user-scoped bookmark ID sets.
packages/…/search.tsDefines the search document and provider contract.
packages/…/vectorStore.tsDefines the vector document, filter rules, and vector-store contract.
packages/…/searchRanking.tsExplains how full-text and semantic ranked lists are combined.
apps/…/searchWorker.tsShows how bookmark data reaches the full-text discovery view.
apps/…/embeddingsWorker.tsShows how bookmark content becomes a vector and reaches the vector view.
packages/…/index.tsDescribes the current Meilisearch full-text provider.
packages/…/index.tsDescribes the current Meilisearch vector and similar-item provider.
apps/…/bookmark-search.tsShows how the dashboard stores search state and requests paged results.

For the wider service context, see Search, inference, and plugins. Related flows include queue execution backends, content ingestion and enrichment jobs, bookmark organization APIs, and web dashboard reader.