> Complete content index: https://narsil.sondelali.com/llms.txt

# Narsil vs Elasticsearch

> The benchmark harness measured Narsil and Elasticsearch for ranking quality, speed, and ingest. Every result is here, including Elasticsearch's wins.

URL: https://narsil.sondelali.com/compare/elasticsearch

## Headline result

On DBpedia 1M hybrid search with equal settings, Narsil answers 1.8 times as many searches a second as Elasticsearch.

Ratio: 1.8× (Elasticsearch's rate).

- Narsil Rust: 1,614
- Narsil TypeScript: 1,304
- Elasticsearch: 904

The DBpedia 1M set contains no human relevance judgements, so the harness reports no nDCG@10 for it.

The harness recorded these figures in run `20261119T135007Z` on 19 November 2026, with Narsil built from commit `3ad47df2c9c1`.

The harness measured Narsil `0.4.5` against Elasticsearch `9.5.6`.

The harness tested Narsil TypeScript on GCP c3-standard-8, us-central1-a; Narsil Rust on GCP c3-standard-8, us-east1-b; and Elasticsearch on GCP c3-standard-8, us-east4-a, each on the processor that its machine reports as Intel(R) Xeon(R) Platinum 8481C CPU @ 2.70GHz.

## What each engine is for

**Elasticsearch.** Elasticsearch is the distributed search and analytics engine from Elastic, and it is built on Apache Lucene. Teams use it for application search, and they also use it to search and analyse logs, metrics, and security events across large clusters.

**Narsil.** Narsil is an open source search engine for application search, with full-text, vector, hybrid, and geo search on one typed index. You can embed it in your application process or deploy it as a server with a REST API, and the TypeScript, Python, Go, and Rust packages all read the same index format.

## Equal settings

Every engine stores full-precision vectors. On the vector track, the harness raises each engine's search effort until that engine reaches an ANN recall@10 of 0.99, before it measures the engine's speed.

### Keyword search

| Dataset | Engine | nDCG@10 | Recall@100 | Ingest docs/s | p50 ms | p99 ms | Peak QPS |
| --- | --- | ---: | ---: | ---: | ---: | ---: | ---: |
| SciFact | Narsil TypeScript | 0.681 | 0.925 | 4,421 | 0.34 | 0.80 | 34,198 (34,169 to 34,213) |
| SciFact | Narsil Rust | 0.681 | 0.925 | 7,529 | 0.26 | 0.40 | 56,315 (56,271 to 56,361) |
| SciFact | Elasticsearch | 0.679 | 0.925 | 3,709 | 2.11 | 3.14 | 7,208 (7,191 to 7,237) |
| NFCorpus | Narsil TypeScript | 0.328 | 0.249 | 4,402 | 0.32 | 0.71 | 51,462 (51,319 to 51,564) |
| NFCorpus | Narsil Rust | 0.328 | 0.249 | 6,717 | 0.22 | 0.31 | 94,225+ (93,724 to 94,639) |
| NFCorpus | Elasticsearch | 0.322 | 0.246 | 6,914 | 0.72 | 1.10 | 13,682 (13,677 to 13,711) |
| DBpedia 100K | Narsil TypeScript | n/a | n/a | 18,039 | 0.30 | 0.64 | 33,054 (32,983 to 33,102) |
| DBpedia 100K | Narsil Rust | n/a | n/a | 35,693 | 0.24 | 0.52 | 53,510 (53,422 to 53,637) |
| DBpedia 100K | Elasticsearch | n/a | n/a | 43,438 | 0.78 | 1.14 | 12,613 (12,538 to 12,641) |
| DBpedia 1M | Narsil TypeScript | n/a | n/a | 18,512 | 0.54 | 2.12 | 8,459 (8,380 to 8,498) |
| DBpedia 1M | Narsil Rust | n/a | n/a | 22,032 | 0.58 | 1.99 | 11,792 (11,749 to 11,803) |
| DBpedia 1M | Elasticsearch | n/a | n/a | 46,821 | 0.91 | 1.65 | 7,789 (7,766 to 7,792) |

A highlighted figure is the best in its column for that dataset.

p50 is the median search time and p99 is the time within which 99% of searches finished, as the client measured them. The table shows each peak with its 95% interval.

A + after a peak means that the load generator reached its limit before the engine did, so the engine's real peak is at least that figure.

The tables show n/a for nDCG@10 and Recall@100 on the DBpedia sets, because those sets contain no human relevance judgements.

### Vector search

| Dataset | Engine | nDCG@10 | Recall@100 | ANN recall@10 | Ingest docs/s | p50 ms | p99 ms | Peak QPS |
| --- | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
| SciFact | Narsil TypeScript | 0.624 | 0.923 | 0.996 | 1,691 | 0.46 | 0.82 | 16,931 (16,925 to 16,999) |
| SciFact | Narsil Rust | 0.624 | 0.923 | 0.996 | 2,374 | 0.37 | 0.49 | 27,162 (27,054 to 27,221) |
| SciFact | Elasticsearch | 0.624 | 0.923 | 0.994 | 1,125 | 1.00 | 1.92 | 8,493 (8,246 to 8,527) |
| NFCorpus | Narsil TypeScript | 0.315 | 0.309 | 0.994 | 1,564 | 0.50 | 0.93 | 13,799 (13,794 to 14,027) |
| NFCorpus | Narsil Rust | 0.315 | 0.309 | 0.991 | 2,273 | 0.44 | 0.54 | 21,238 (21,167 to 21,265) |
| NFCorpus | Elasticsearch | 0.315 | 0.309 | 0.990 | 1,230 | 1.11 | 1.32 | 7,288 (7,138 to 7,290) |
| DBpedia 100K | Narsil TypeScript | n/a | n/a | 0.991 | 850 | 1.49 | 2.18 | 3,589 (3,567 to 3,592) |
| DBpedia 100K | Narsil Rust | n/a | n/a | 0.991 | 886 | 1.41 | 1.93 | 4,794 (4,660 to 5,195) |
| DBpedia 100K | Elasticsearch | n/a | n/a | 0.992 | 562 | 3.06 | 4.99 | 1,955 (1,921 to 1,965) |
| DBpedia 1M | Narsil TypeScript | n/a | n/a | 0.992 | 743 | 3.45 | 4.79 | 1,659 (1,631 to 1,663) |
| DBpedia 1M | Narsil Rust | n/a | n/a | 0.992 | 878 | 3.18 | 4.37 | 1,971 (1,849 to 2,005) |
| DBpedia 1M | Elasticsearch | n/a | n/a | 0.991 | 503 | 5.75 | 10.89 | 1,118 (1,100 to 1,133) |

A highlighted figure is the best in its column for that dataset.

p50 is the median search time and p99 is the time within which 99% of searches finished, as the client measured them. The table shows each peak with its 95% interval.

The tables show n/a for nDCG@10 and Recall@100 on the DBpedia sets, because those sets contain no human relevance judgements.

### Hybrid search

| Dataset | Engine | nDCG@10 | Recall@100 | Ingest docs/s | p50 ms | p99 ms | Peak QPS |
| --- | --- | ---: | ---: | ---: | ---: | ---: | ---: |
| SciFact | Narsil TypeScript | 0.705 | 0.964 | 1,989 | 0.68 | 1.07 | 11,835 (11,798 to 11,838) |
| SciFact | Narsil Rust | 0.705 | 0.964 | 2,333 | 0.50 | 0.63 | 19,998 (19,936 to 20,005) |
| SciFact | Elasticsearch | 0.708 | 0.961 | 1,454 | 2.23 | 2.98 | 3,678 (3,673 to 3,721) |
| NFCorpus | Narsil TypeScript | 0.356 | 0.324 | 1,590 | 0.63 | 1.02 | 11,604 (11,578 to 11,613) |
| NFCorpus | Narsil Rust | 0.356 | 0.324 | 2,093 | 0.49 | 0.63 | 18,913 (18,884 to 18,916) |
| NFCorpus | Elasticsearch | 0.352 | 0.322 | 1,179 | 1.61 | 1.90 | 4,555 (4,523 to 4,585) |
| DBpedia 100K | Narsil TypeScript | n/a | n/a | 855 | 1.62 | 2.37 | 3,218 (3,172 to 3,228) |
| DBpedia 100K | Narsil Rust | n/a | n/a | 879 | 1.46 | 1.98 | 4,647 (4,423 to 4,736) |
| DBpedia 100K | Elasticsearch | n/a | n/a | 551 | 3.53 | 5.39 | 1,562 (1,558 to 1,579) |
| DBpedia 1M | Narsil TypeScript | n/a | n/a | 704 | 4.01 | 6.18 | 1,304 (1,280 to 1,310) |
| DBpedia 1M | Narsil Rust | n/a | n/a | 880 | 3.76 | 5.50 | 1,614 (1,596 to 1,650) |
| DBpedia 1M | Elasticsearch | n/a | n/a | 445 | 6.51 | 11.80 | 904 (896 to 917) |

A highlighted figure is the best in its column for that dataset.

p50 is the median search time and p99 is the time within which 99% of searches finished, as the client measured them. The table shows each peak with its 95% interval.

The tables show n/a for nDCG@10 and Recall@100 on the DBpedia sets, because those sets contain no human relevance judgements.

## Recommended production settings

Each engine stores vectors in the compressed form that its documentation recommends for production, which the Vector storage column shows. However, each engine has to reach an ANN recall@10 of 0.99 before the harness measures its speed.

### Vector search

| Dataset | Engine | nDCG@10 | Recall@100 | ANN recall@10 | Vector storage | Ingest docs/s | p50 ms | p99 ms | Peak QPS |
| --- | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
| SciFact | Narsil TypeScript | 0.624 | 0.923 | 0.993 | OSQ 4-bit | 2,100 | 0.39 | 0.76 | 15,809 (15,756 to 15,840) |
| SciFact | Narsil Rust | 0.624 | 0.923 | 0.995 | OSQ 4-bit | 2,367 | 0.34 | 0.47 | 30,671 (30,602 to 30,696) |
| SciFact | Elasticsearch | 0.624 | 0.923 | 0.991 | BBQ | 1,431 | 1.05 | 1.23 | 7,656 (7,553 to 7,680) |
| NFCorpus | Narsil TypeScript | 0.315 | 0.309 | 0.993 | OSQ 4-bit | 1,562 | 0.43 | 0.80 | 13,309 (13,273 to 13,336) |
| NFCorpus | Narsil Rust | 0.315 | 0.309 | 0.993 | OSQ 4-bit | 1,995 | 0.41 | 0.54 | 23,795 (23,768 to 23,836) |
| NFCorpus | Elasticsearch | 0.315 | 0.309 | 0.985 | BBQ | 1,396 | 1.24 | 1.61 | 5,917 (below target) |
| DBpedia 100K | Narsil TypeScript | n/a | n/a | 0.992 | OSQ 4-bit | 818 | 0.86 | 1.38 | 5,522 (5,462 to 5,536) |
| DBpedia 100K | Narsil Rust | n/a | n/a | 0.991 | OSQ 4-bit | 879 | 0.78 | 1.01 | 9,341 (9,285 to 9,465) |
| DBpedia 100K | Elasticsearch | n/a | n/a | 0.992 | BBQ | 587 | 2.24 | 3.00 | 3,010 (3,009 to 3,046) |
| DBpedia 1M | Narsil TypeScript | n/a | n/a | 0.992 | OSQ 4-bit | 542 | 1.58 | 2.33 | 3,766 (3,586 to 3,931) |
| DBpedia 1M | Narsil Rust | n/a | n/a | 0.992 | OSQ 4-bit | 882 | 1.77 | 2.36 | 3,847 (3,716 to 3,879) |
| DBpedia 1M | Elasticsearch | n/a | n/a | 0.994 | BBQ | 555 | 4.99 | 8.16 | 1,479 (1,476 to 1,491) |

A highlighted figure is the best in its column for that dataset.

p50 is the median search time and p99 is the time within which 99% of searches finished, as the client measured them. The table shows each peak with its 95% interval.

Below target marks an engine that missed the recall target, so the verdicts further down omit its speed.

The tables show n/a for nDCG@10 and Recall@100 on the DBpedia sets, because those sets contain no human relevance judgements.

### Hybrid search

| Dataset | Engine | nDCG@10 | Recall@100 | Vector storage | Ingest docs/s | p50 ms | p99 ms | Peak QPS |
| --- | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
| SciFact | Narsil TypeScript | 0.705 | 0.964 | OSQ 4-bit | 2,012 | 0.61 | 0.92 | 10,572 (10,571 to 10,709) |
| SciFact | Narsil Rust | 0.705 | 0.964 | OSQ 4-bit | 2,398 | 0.47 | 0.61 | 21,782 (21,769 to 21,888) |
| SciFact | Elasticsearch | 0.706 | 0.961 | BBQ | 1,537 | 1.83 | 2.33 | 3,610 (3,586 to 3,619) |
| NFCorpus | Narsil TypeScript | 0.356 | 0.324 | OSQ 4-bit | 1,626 | 0.61 | 0.95 | 10,784 (10,711 to 10,926) |
| NFCorpus | Narsil Rust | 0.356 | 0.324 | OSQ 4-bit | 1,939 | 0.43 | 0.58 | 21,494 (21,487 to 21,504) |
| NFCorpus | Elasticsearch | 0.352 | 0.321 | BBQ | 1,384 | 1.72 | 1.99 | 4,056 (4,051 to 4,057) |
| DBpedia 100K | Narsil TypeScript | n/a | n/a | OSQ 4-bit | 812 | 1.02 | 1.62 | 4,789 (4,749 to 4,795) |
| DBpedia 100K | Narsil Rust | n/a | n/a | OSQ 4-bit | 876 | 0.91 | 1.21 | 8,433 (8,425 to 8,540) |
| DBpedia 100K | Elasticsearch | n/a | n/a | BBQ | 511 | 2.80 | 3.61 | 2,367 (2,353 to 2,377) |
| DBpedia 1M | Narsil TypeScript | n/a | n/a | OSQ 4-bit | 572 | 2.56 | 6.42 | 2,492 (2,471 to 2,508) |
| DBpedia 1M | Narsil Rust | n/a | n/a | OSQ 4-bit | 881 | 2.49 | 4.14 | 2,756 (2,752 to 2,761) |
| DBpedia 1M | Elasticsearch | n/a | n/a | BBQ | 543 | 5.73 | 9.24 | 1,208 (1,200 to 1,214) |

A highlighted figure is the best in its column for that dataset.

p50 is the median search time and p99 is the time within which 99% of searches finished, as the client measured them. The table shows each peak with its 95% interval.

The tables show n/a for nDCG@10 and Recall@100 on the DBpedia sets, because those sets contain no human relevance judgements.

## Where Narsil is better

- Narsil can work inside your application process, where it answers each search without a network call. Once you need a server, a Narsil server can load that same index without any change.
- The same engine works in a browser and stores its index in IndexedDB, so your users can search while their device is offline.
- Narsil keeps text, vectors, and coordinates in one typed index, so a single query can combine text, vector, and geo conditions.

Of the 136 measurements that the harness recorded for both engines, Narsil came out ahead in 117 and Elasticsearch in 11, while 8 came out level.

A peak is level when the two 95% intervals overlap, or when the load generator capped the lower peak, because that figure is then a lower bound. Every other measure is level when the tables above show the same figure for both engines.

### nDCG@10

Narsil better in 8 of 20.

| Comparison | Narsil | Elasticsearch |
| --- | ---: | ---: |
| Keyword, SciFact (equal, Narsil TypeScript) | 0.681 | 0.679 |
| Keyword, SciFact (equal, Narsil Rust) | 0.681 | 0.679 |
| Keyword, NFCorpus (equal, Narsil TypeScript) | 0.328 | 0.322 |
| Keyword, NFCorpus (equal, Narsil Rust) | 0.328 | 0.322 |
| Hybrid, NFCorpus (equal, Narsil TypeScript) | 0.356 | 0.352 |
| Hybrid, NFCorpus (equal, Narsil Rust) | 0.356 | 0.352 |
| Hybrid, NFCorpus (recommended, Narsil TypeScript) | 0.356 | 0.352 |
| Hybrid, NFCorpus (recommended, Narsil Rust) | 0.356 | 0.352 |

### Peak queries a second

Narsil better in 38 of 38.

| Comparison | Narsil | Elasticsearch |
| --- | ---: | ---: |
| Keyword, SciFact (equal, Narsil TypeScript) | 34,198 | 7,208 |
| Keyword, SciFact (equal, Narsil Rust) | 56,315 | 7,208 |
| Keyword, NFCorpus (equal, Narsil TypeScript) | 51,462 | 13,682 |
| Keyword, NFCorpus (equal, Narsil Rust) | 94,225 | 13,682 |
| Keyword, DBpedia 100K (equal, Narsil TypeScript) | 33,054 | 12,613 |
| Keyword, DBpedia 100K (equal, Narsil Rust) | 53,510 | 12,613 |
| Keyword, DBpedia 1M (equal, Narsil TypeScript) | 8,459 | 7,789 |
| Keyword, DBpedia 1M (equal, Narsil Rust) | 11,792 | 7,789 |
| Vector, SciFact (equal, Narsil TypeScript) | 16,931 | 8,493 |
| Vector, SciFact (equal, Narsil Rust) | 27,162 | 8,493 |
| Vector, NFCorpus (equal, Narsil TypeScript) | 13,799 | 7,288 |
| Vector, NFCorpus (equal, Narsil Rust) | 21,238 | 7,288 |
| Vector, DBpedia 100K (equal, Narsil TypeScript) | 3,589 | 1,955 |
| Vector, DBpedia 100K (equal, Narsil Rust) | 4,794 | 1,955 |
| Vector, DBpedia 1M (equal, Narsil TypeScript) | 1,659 | 1,118 |
| Vector, DBpedia 1M (equal, Narsil Rust) | 1,971 | 1,118 |
| Hybrid, SciFact (equal, Narsil TypeScript) | 11,835 | 3,678 |
| Hybrid, SciFact (equal, Narsil Rust) | 19,998 | 3,678 |
| Hybrid, NFCorpus (equal, Narsil TypeScript) | 11,604 | 4,555 |
| Hybrid, NFCorpus (equal, Narsil Rust) | 18,913 | 4,555 |
| Hybrid, DBpedia 100K (equal, Narsil TypeScript) | 3,218 | 1,562 |
| Hybrid, DBpedia 100K (equal, Narsil Rust) | 4,647 | 1,562 |
| Hybrid, DBpedia 1M (equal, Narsil TypeScript) | 1,304 | 904 |
| Hybrid, DBpedia 1M (equal, Narsil Rust) | 1,614 | 904 |
| Vector, SciFact (recommended, Narsil TypeScript) | 15,809 | 7,656 |
| Vector, SciFact (recommended, Narsil Rust) | 30,671 | 7,656 |
| Vector, DBpedia 100K (recommended, Narsil TypeScript) | 5,522 | 3,010 |
| Vector, DBpedia 100K (recommended, Narsil Rust) | 9,341 | 3,010 |
| Vector, DBpedia 1M (recommended, Narsil TypeScript) | 3,766 | 1,479 |
| Vector, DBpedia 1M (recommended, Narsil Rust) | 3,847 | 1,479 |
| Hybrid, SciFact (recommended, Narsil TypeScript) | 10,572 | 3,610 |
| Hybrid, SciFact (recommended, Narsil Rust) | 21,782 | 3,610 |
| Hybrid, NFCorpus (recommended, Narsil TypeScript) | 10,784 | 4,056 |
| Hybrid, NFCorpus (recommended, Narsil Rust) | 21,494 | 4,056 |
| Hybrid, DBpedia 100K (recommended, Narsil TypeScript) | 4,789 | 2,367 |
| Hybrid, DBpedia 100K (recommended, Narsil Rust) | 8,433 | 2,367 |
| Hybrid, DBpedia 1M (recommended, Narsil TypeScript) | 2,492 | 1,208 |
| Hybrid, DBpedia 1M (recommended, Narsil Rust) | 2,756 | 1,208 |

### Median client latency, ms

Narsil better in 38 of 38.

| Comparison | Narsil | Elasticsearch |
| --- | ---: | ---: |
| Keyword, SciFact (equal, Narsil TypeScript) | 0.34 | 2.11 |
| Keyword, SciFact (equal, Narsil Rust) | 0.26 | 2.11 |
| Keyword, NFCorpus (equal, Narsil TypeScript) | 0.32 | 0.72 |
| Keyword, NFCorpus (equal, Narsil Rust) | 0.22 | 0.72 |
| Keyword, DBpedia 100K (equal, Narsil TypeScript) | 0.30 | 0.78 |
| Keyword, DBpedia 100K (equal, Narsil Rust) | 0.24 | 0.78 |
| Keyword, DBpedia 1M (equal, Narsil TypeScript) | 0.54 | 0.91 |
| Keyword, DBpedia 1M (equal, Narsil Rust) | 0.58 | 0.91 |
| Vector, SciFact (equal, Narsil TypeScript) | 0.46 | 1.00 |
| Vector, SciFact (equal, Narsil Rust) | 0.37 | 1.00 |
| Vector, NFCorpus (equal, Narsil TypeScript) | 0.50 | 1.11 |
| Vector, NFCorpus (equal, Narsil Rust) | 0.44 | 1.11 |
| Vector, DBpedia 100K (equal, Narsil TypeScript) | 1.49 | 3.06 |
| Vector, DBpedia 100K (equal, Narsil Rust) | 1.41 | 3.06 |
| Vector, DBpedia 1M (equal, Narsil TypeScript) | 3.45 | 5.75 |
| Vector, DBpedia 1M (equal, Narsil Rust) | 3.18 | 5.75 |
| Hybrid, SciFact (equal, Narsil TypeScript) | 0.68 | 2.23 |
| Hybrid, SciFact (equal, Narsil Rust) | 0.50 | 2.23 |
| Hybrid, NFCorpus (equal, Narsil TypeScript) | 0.63 | 1.61 |
| Hybrid, NFCorpus (equal, Narsil Rust) | 0.49 | 1.61 |
| Hybrid, DBpedia 100K (equal, Narsil TypeScript) | 1.62 | 3.53 |
| Hybrid, DBpedia 100K (equal, Narsil Rust) | 1.46 | 3.53 |
| Hybrid, DBpedia 1M (equal, Narsil TypeScript) | 4.01 | 6.51 |
| Hybrid, DBpedia 1M (equal, Narsil Rust) | 3.76 | 6.51 |
| Vector, SciFact (recommended, Narsil TypeScript) | 0.39 | 1.05 |
| Vector, SciFact (recommended, Narsil Rust) | 0.34 | 1.05 |
| Vector, DBpedia 100K (recommended, Narsil TypeScript) | 0.86 | 2.24 |
| Vector, DBpedia 100K (recommended, Narsil Rust) | 0.78 | 2.24 |
| Vector, DBpedia 1M (recommended, Narsil TypeScript) | 1.58 | 4.99 |
| Vector, DBpedia 1M (recommended, Narsil Rust) | 1.77 | 4.99 |
| Hybrid, SciFact (recommended, Narsil TypeScript) | 0.61 | 1.83 |
| Hybrid, SciFact (recommended, Narsil Rust) | 0.47 | 1.83 |
| Hybrid, NFCorpus (recommended, Narsil TypeScript) | 0.61 | 1.72 |
| Hybrid, NFCorpus (recommended, Narsil Rust) | 0.43 | 1.72 |
| Hybrid, DBpedia 100K (recommended, Narsil TypeScript) | 1.02 | 2.80 |
| Hybrid, DBpedia 100K (recommended, Narsil Rust) | 0.91 | 2.80 |
| Hybrid, DBpedia 1M (recommended, Narsil TypeScript) | 2.56 | 5.73 |
| Hybrid, DBpedia 1M (recommended, Narsil Rust) | 2.49 | 5.73 |

### Documents ingested a second

Narsil better in 33 of 40.

| Comparison | Narsil | Elasticsearch |
| --- | ---: | ---: |
| Keyword, SciFact (equal, Narsil TypeScript) | 4,421 | 3,709 |
| Keyword, SciFact (equal, Narsil Rust) | 7,529 | 3,709 |
| Vector, SciFact (equal, Narsil TypeScript) | 1,691 | 1,125 |
| Vector, SciFact (equal, Narsil Rust) | 2,374 | 1,125 |
| Vector, NFCorpus (equal, Narsil TypeScript) | 1,564 | 1,230 |
| Vector, NFCorpus (equal, Narsil Rust) | 2,273 | 1,230 |
| Vector, DBpedia 100K (equal, Narsil TypeScript) | 850 | 562 |
| Vector, DBpedia 100K (equal, Narsil Rust) | 886 | 562 |
| Vector, DBpedia 1M (equal, Narsil TypeScript) | 743 | 503 |
| Vector, DBpedia 1M (equal, Narsil Rust) | 878 | 503 |
| Hybrid, SciFact (equal, Narsil TypeScript) | 1,989 | 1,454 |
| Hybrid, SciFact (equal, Narsil Rust) | 2,333 | 1,454 |
| Hybrid, NFCorpus (equal, Narsil TypeScript) | 1,590 | 1,179 |
| Hybrid, NFCorpus (equal, Narsil Rust) | 2,093 | 1,179 |
| Hybrid, DBpedia 100K (equal, Narsil TypeScript) | 855 | 551 |
| Hybrid, DBpedia 100K (equal, Narsil Rust) | 879 | 551 |
| Hybrid, DBpedia 1M (equal, Narsil TypeScript) | 704 | 445 |
| Hybrid, DBpedia 1M (equal, Narsil Rust) | 880 | 445 |
| Vector, SciFact (recommended, Narsil TypeScript) | 2,100 | 1,431 |
| Vector, SciFact (recommended, Narsil Rust) | 2,367 | 1,431 |
| Vector, NFCorpus (recommended, Narsil TypeScript) | 1,562 | 1,396 |
| Vector, NFCorpus (recommended, Narsil Rust) | 1,995 | 1,396 |
| Vector, DBpedia 100K (recommended, Narsil TypeScript) | 818 | 587 |
| Vector, DBpedia 100K (recommended, Narsil Rust) | 879 | 587 |
| Vector, DBpedia 1M (recommended, Narsil Rust) | 882 | 555 |
| Hybrid, SciFact (recommended, Narsil TypeScript) | 2,012 | 1,537 |
| Hybrid, SciFact (recommended, Narsil Rust) | 2,398 | 1,537 |
| Hybrid, NFCorpus (recommended, Narsil TypeScript) | 1,626 | 1,384 |
| Hybrid, NFCorpus (recommended, Narsil Rust) | 1,939 | 1,384 |
| Hybrid, DBpedia 100K (recommended, Narsil TypeScript) | 812 | 511 |
| Hybrid, DBpedia 100K (recommended, Narsil Rust) | 876 | 511 |
| Hybrid, DBpedia 1M (recommended, Narsil TypeScript) | 572 | 543 |
| Hybrid, DBpedia 1M (recommended, Narsil Rust) | 881 | 543 |

## Where Elasticsearch is better

- Elastic builds its observability and security products on Elasticsearch, whose aggregations can summarise large volumes of log, metric, and security events.
- Elastic maintains Kibana for dashboards, along with official client libraries for many languages.
- Elasticsearch has a long record in production, so its documentation and community forums cover many of the operational problems that a team can meet.
- Elastic sells Elasticsearch as a managed service, Elastic Cloud, so you can search without operating a cluster yourself.

Measurements that Elasticsearch won:

### nDCG@10

Elasticsearch better in 4 of 20.

| Comparison | Narsil | Elasticsearch |
| --- | ---: | ---: |
| Hybrid, SciFact (equal, Narsil TypeScript) | 0.705 | 0.708 |
| Hybrid, SciFact (equal, Narsil Rust) | 0.705 | 0.708 |
| Hybrid, SciFact (recommended, Narsil TypeScript) | 0.705 | 0.706 |
| Hybrid, SciFact (recommended, Narsil Rust) | 0.705 | 0.706 |

### Documents ingested a second

Elasticsearch better in 7 of 40.

| Comparison | Narsil | Elasticsearch |
| --- | ---: | ---: |
| Keyword, NFCorpus (equal, Narsil TypeScript) | 4,402 | 6,914 |
| Keyword, NFCorpus (equal, Narsil Rust) | 6,717 | 6,914 |
| Keyword, DBpedia 100K (equal, Narsil TypeScript) | 18,039 | 43,438 |
| Keyword, DBpedia 100K (equal, Narsil Rust) | 35,693 | 43,438 |
| Keyword, DBpedia 1M (equal, Narsil TypeScript) | 18,512 | 46,821 |
| Keyword, DBpedia 1M (equal, Narsil Rust) | 22,032 | 46,821 |
| Vector, DBpedia 1M (recommended, Narsil TypeScript) | 542 | 555 |

## Try Narsil

When you paste this prompt into your coding agent, the agent will install the Narsil skill and the package, then build and test the search that your project needs.

```text
Read https://narsil.sondelali.com/agents.md and follow it to add Narsil search to this project.
```

If you prefer to write the code yourself, you can use the Narsil package for TypeScript, Python, Go, or Rust, since every package searches with the same engine. Each program indexes three films and finds the films from 1990 onwards whose title matches ronin, before it finds the two films whose embeddings are closest to a query vector.

```bash title="pnpm" tab="TypeScript"
pnpm add @delali/narsil
```

```bash title="pip" tab="Python"
pip install delali-narsil
```

```bash title="go get" tab="Go"
go get github.com/assetcorp/narsil/packages/go/engine@v0.2.1
```

```bash title="cargo" tab="Rust"
cargo add delali-narsil
```

```ts title="films.ts" tab="TypeScript"
import { createNarsil } from '@delali/narsil'

const narsil = await createNarsil()

await narsil.createIndex('films', {
  schema: { title: 'string', year: 'number', embedding: 'vector[3]' },
})

await narsil.insertBatch('films', [
  { id: 'heat', title: 'Heat', year: 1995, embedding: [0.9, 0.1, 0.2] },
  { id: 'ronin', title: 'Ronin', year: 1998, embedding: [0.8, 0.3, 0.1] },
  { id: 'solaris', title: 'Solaris', year: 1972, embedding: [0.1, 0.9, 0.7] },
])

const keyword = await narsil.query('films', { term: 'ronin', filters: { fields: { year: { gte: 1990 } } } })
console.log(keyword.count, keyword.hits[0].id)

const nearest = await narsil.query('films', {
  vector: { field: 'embedding', value: [0.85, 0.2, 0.15] },
  limit: 2,
})
for (const hit of nearest.hits) {
  console.log(hit.id, hit.score)
}

await narsil.shutdown()
```

```python title="films.py" tab="Python"
from narsil import Narsil

with Narsil() as engine:
    engine.create_index("films", {"schema": {"title": "string", "year": "number", "embedding": "vector[3]"}})
    engine.insert_batch(
        "films",
        [
            {"id": "heat", "title": "Heat", "year": 1995, "embedding": [0.9, 0.1, 0.2]},
            {"id": "ronin", "title": "Ronin", "year": 1998, "embedding": [0.8, 0.3, 0.1]},
            {"id": "solaris", "title": "Solaris", "year": 1972, "embedding": [0.1, 0.9, 0.7]},
        ],
    )

    keyword = engine.query("films", {"term": "ronin", "filters": {"fields": {"year": {"gte": 1990}}}})
    print(keyword["count"], keyword["hits"][0]["id"])

    nearest = engine.query("films", {"vector": {"field": "embedding", "value": [0.85, 0.2, 0.15]}, "limit": 2})
    for hit in nearest["hits"]:
        print(hit["id"], hit["score"])
```

```go title="main.go" tab="Go"
package main

import (
	"context"
	"fmt"
	"log"

	"github.com/assetcorp/narsil/packages/go/engine"
)

func main() {
	if err := run(context.Background(), "./narsil-data"); err != nil {
		log.Fatal(err)
	}
}

func run(ctx context.Context, directory string) error {
	narsil, err := engine.New(ctx, engine.Config{
		Durability: &engine.DurabilityConfig{Directory: directory},
	})
	if err != nil {
		return err
	}
	defer narsil.Shutdown(ctx)

	err = narsil.CreateIndex(ctx, "films", engine.IndexConfig{
		Schema: engine.Schema{
			"title":     engine.FieldString,
			"year":      engine.FieldNumber,
			"embedding": engine.VectorFieldType(3),
		},
	})
	if err != nil {
		return err
	}

	_, err = narsil.InsertBatch(ctx, "films", []*engine.Document{
		engine.DocumentFromMap(map[string]any{"id": "heat", "title": "Heat", "year": 1995, "embedding": []float32{0.9, 0.1, 0.2}}),
		engine.DocumentFromMap(map[string]any{"id": "ronin", "title": "Ronin", "year": 1998, "embedding": []float32{0.8, 0.3, 0.1}}),
		engine.DocumentFromMap(map[string]any{"id": "solaris", "title": "Solaris", "year": 1972, "embedding": []float32{0.1, 0.9, 0.7}}),
	}, engine.InsertOptions{})
	if err != nil {
		return err
	}

	keyword, err := narsil.Query(ctx, "films", engine.QueryParams{
		Term: "ronin",
		Filters: &engine.FilterExpression{Fields: map[string]engine.FieldFilter{
			"year": {Gte: engine.NumberBound(1990)},
		}},
	})
	if err != nil {
		return err
	}
	fmt.Println(keyword.Count, keyword.Hits[0].ID)

	nearest, err := narsil.Query(ctx, "films", engine.QueryParams{
		Mode:   engine.SearchVector,
		Vector: &engine.VectorQueryConfig{Field: "embedding", Value: []float32{0.85, 0.2, 0.15}},
		Limit:  engine.Some(2),
	})
	if err != nil {
		return err
	}
	for _, hit := range nearest.Hits {
		fmt.Println(hit.ID, hit.Score.Or(0))
	}
	return nil
}
```

```rust title="main.rs" tab="Rust"
use narsil::{IndexConfig, Narsil, NarsilConfig, QueryParams, Value, VectorQuery, parse_json};

fn main() -> narsil::Result<()> {
    let engine = Narsil::open(NarsilConfig::default())?;
    engine.create_index(
        "films",
        IndexConfig {
            schema: parse_json(r#"{ "title": "string", "year": "number", "embedding": "vector[3]" }"#)?,
            ..IndexConfig::default()
        },
    )?;

    let films = [
        r#"{ "id": "heat", "title": "Heat", "year": 1995, "embedding": [0.9, 0.1, 0.2] }"#,
        r#"{ "id": "ronin", "title": "Ronin", "year": 1998, "embedding": [0.8, 0.3, 0.1] }"#,
        r#"{ "id": "solaris", "title": "Solaris", "year": 1972, "embedding": [0.1, 0.9, 0.7] }"#,
    ];
    let mut documents = Vec::new();
    for film in films {
        if let Value::Object(document) = parse_json(film)? {
            documents.push(document);
        }
    }
    engine.insert_batch("films", documents)?;

    let keyword = engine.query(
        "films",
        &QueryParams {
            term: Some("ronin".into()),
            filters: Some(parse_json(r#"{ "fields": { "year": { "gte": 1990 } } }"#)?),
            ..QueryParams::default()
        },
    )?;
    println!("{} {}", keyword.count, keyword.hits[0].id);

    let nearest = engine.query(
        "films",
        &QueryParams {
            vector: Some(VectorQuery {
                field: "embedding".into(),
                value: Some(vec![0.85, 0.2, 0.15]),
                ..VectorQuery::default()
            }),
            limit: Some(2),
            ..QueryParams::default()
        },
    )?;
    for hit in &nearest.hits {
        println!("{} {}", hit.id, hit.score.unwrap_or(0.0));
    }
    Ok(())
}
```

- [Serve Narsil over HTTP](https://narsil.sondelali.com/docs/http-server)

## Reproduce these numbers

The benchmark harness is in the Narsil repository, where it writes every figure that it measures into a new run directory.

```bash
git clone https://github.com/assetcorp/narsil.git
cd narsil/benchmarks/server
./run-all.sh narsil narsil-rust elasticsearch
```

- [Open the run on GitHub](https://github.com/assetcorp/narsil/tree/main/benchmarks/server/results/runs/20261119T135007Z)
- [Compare every engine in BENCHMARKS.md](https://github.com/assetcorp/narsil/blob/main/BENCHMARKS.md)
