Narsil documentation
Narsil is an open source search engine with full-text, vector, hybrid, and geosearch on one typed index. It embeds in your app or serves a REST API behind its own server, and recorded benchmark runs score it against the engines on either side of it.
Getting started
2 guides
Getting started27 min readInstall Narsil in TypeScript, Python, Go, or Rust, create a typed index, fill it with a catalogue, and read a ranked result with the matched words marked.Upgrading to 0.410 min readUpdate a Narsil 0.3 application to 0.4.1, with the changes that 0.4 makes to whole-value filters on text fields, filters on undeclared fields, groups, snapshots, 0.3 indexes on disk, partition limits, and the inputs that it refuses, and move a 0.4 application to 0.4.6, whose engine leaves vector fields out of reads.
Languages
3 guides
Python10 min readInstall Narsil in a Python program, map the names in these docs onto the Python package, store an index on disk, ask for the vector fields on a read, read the package's errors, and write a tokeniser in Python.Go10 min readInstall the Narsil Go module, build it for each platform, map the names in these docs onto Go's types, store an index on disk, read its errors, and write a tokeniser in Go.Rust8 min readAdd the Narsil crate to a Rust program, map the names in these docs onto its types, store an index on disk, read the crate's errors, write a tokeniser in Rust, and share one engine between threads.
Core concepts
6 guides
Indexes and documents64 min readDeclare a typed schema, store documents under their ids, read and page through them, change them, give a live index new stop words, and copy its documents through an export.Full-text search86 min readRank documents with BM25, choose which fields the engine searches, match through typos, mark the matches, search a phrase, find a word inside a longer word, add synonyms, and tune the ranking on a live index.Filters and facets100 min readNarrow a search to the documents whose fields pass your tests, match part of a value or a pattern, match a code through a typo, compare text by its order, and count the values of each field for a filter sidebar.Sorting, grouping, and pagination58 min readOrder hits by field values, collapse them into groups with a reducer, page through them by offset or by cursor, browse an index in any order, and pin a result in place.Language support21 min readIndex text in French and Chinese, register a tokeniser and a stop word set, write a custom language module, and rebuild an index after a language changes.Errors23 min readRead the code on a Narsil failure in TypeScript, Python, Go, or Rust, recover from the failure that you expect, and see which field names the engine refuses in a query.
Search modes
6 guides
Vector search33 min readEmbed text with a model inside your process, store the vectors in a typed field, and search by meaning in TypeScript, Python, Go, or Rust, with a similarity floor, a graph that the engine builds as the field grows, and compaction after a removal.Hybrid search35 min readSearch one index for keywords and for meaning at once in TypeScript, Python, Go, or Rust, read the two rankings behind the fused order, weight one side with the linear blend, and keep the same order on every page.Geosearch23 min readStore coordinates in a geopoint field in TypeScript, Python, Go, or Rust, keep the documents inside a radius or a polygon, flip either test, and filter across the antimeridian without a search term.Embedding adapters33 min readWrite or install an embedding adapter in TypeScript, Python, Go, or Rust, let the engine embed your text on every write and every search, store the rest of a batch when one document has no text, and wrap the adapter in a cache.Reranking30 min readReorder the top hits of a search with a cross-encoder that scores the question and each hit together, from a model in your process in TypeScript, Python, Go, or Rust, or from a hosted rerank service in TypeScript.Query suggestions17 min readOffer whole searches that enough different people make and follow with a click, by counting those searches in TypeScript, Python, Go, or Rust and publishing the popular ones to an ordinary index that your application can query.
Operations
9 guides
Configuration17 min readSet up one engine for production in TypeScript, Python, Go, or Rust, check every write and search with a plugin, and look up each engine and index option with its default.Persistence and durability47 min readRecover every acknowledged write after a restart, choose how many writes you can lose in a crash, see how much disk space an index takes up, search an index larger than memory, close idle indexes, and move an index as a snapshot or an export.Partitions and workers17 min readSplit an index across partitions, get a warning before it fills, reshape it while it answers searches, and spread its searches across threads in TypeScript and Go.Observability21 min readRead what each index stores in memory and on disk, report the memory that the engine uses, alert on the work that the engine does in the background, and probe a server from a load balancer.Native search core8 min readSee which search work Narsil does in its C core, what each language needs to build or load that core, how to fail a deployment that lacks it, and how to keep a bundler from leaving it out.HTTP server22 min readServe an engine over HTTP from TypeScript or Rust, admit only the callers that hold a token, call it from TypeScript, Python, or Go, generate a client from its OpenAPI description, and stop it so that the process exits cleanly.Container image23 min readStart a Narsil node from the published container image, search it from TypeScript, Python, or Go, choose between the TypeScript and Rust servers, and set the node up through environment variables.Cluster33 min readSpread an index across several nodes that each store copies of its partitions, wait until every copy is in place, and back the index up to a directory, S3, or Google Cloud Storage so that you can restore it onto a cluster of any size.Change capture25 min readFollow every insert, update, and removal on an index from a saved position, see each document as it stood before the write, receive only the changes that match a filter, and start again from an export when the feed sends a resync.
Clients
6 guides
TypeScript client12 min readReach a Narsil server from Node, a browser, or an edge function with the same calls as the embedded engine, spread the requests across several servers, and handle the tasks, deadlines, and failures of a network call.Python client15 min readReach a Narsil server from Python through a blocking client or an async one, write and search documents, follow a rebalance, and keep working while one of several servers is down.Go client18 min readReach a Narsil server from Go through a client that depends on the standard library alone, write and search documents, follow a rebalance, and keep working while one of several servers is down.React hooks9 min readGive a React tree one Narsil client or one engine in the page, search as somebody types, offer completions under the box, and read documents, stats, and tasks through hooks that share their requests.React Native13 min readSearch an index that an iOS or Android app stores on the phone, so that search works offline and the index stays on the phone after the app closes.Device sync17 min readKeep a copy of one user's index on a phone, a laptop, or a browser tab, so that the app searches and writes while it is offline and uploads its writes once it reconnects.
AI agents
9 guides
Overview4 min readRead what one Narsil search returns to an AI agent, and find the guide for each failure that a person can notice.Cite the passage behind an answer16 min readGive every answer from an AI agent the rule's reference and its exact sentence, and check the quote against the stored text before a passenger reads it.Give a model a search tool15 min readGive a model a search tool that takes a resident's words, since a lookup by key needs an identifier that the model has no way of knowing.Give each client a separate index12 min readGive each client's AI agent a separate index, because the engine ranks passages by relevance and can put another client's handbook first.Fit the passages in a context budget17 min readMeasure the characters that a search tool returns, set each passage's cap from the text that it has to include, and keep the total within a budget.When the index has no good match14 min readRequire every query term and return a retrieval status that the AI agent states first, since a near miss looks like an answer and an empty result can lead the model to guess.Keep the index current12 min readWrite every change in your records to the index as an update or a removal, and wait for the worker copies, since the index holds the version from your last write to it.Record every search13 min readRecord every query and every preflight with one plugin on the engine, so that your journal includes the searches from every tool.Search by wording and by meaning12 min readAdd the customer's words to the catalogue and fuse the keyword and vector rankings, since the engine puts the right product first for this customer only when it fuses the two.