sonic README

The project's README from github.com/valeriansaliou/sonic. As one markdown file: README.md.

Sonic

dependency status Buy Me A Coffee

Sonic is a fast, lightweight and schema-less search backend. It ingests search texts and identifier tuples that can then be queried against in a microsecond's time.

Sonic can be used as a simple alternative to super-heavy and full-featured search backends such as Elasticsearch in some use-cases. It is capable of normalizing natural language search queries, auto-completing a search query and providing the most relevant results for a query. Sonic is an identifier index, rather than a document index; when queried, it returns IDs that can then be used to refer to the matched documents in an external database.

A strong attention to performance and code cleanliness has been given when designing Sonic. It aims at being crash-free, super-fast and puts minimum strain on server resources (our measurements have shown that Sonic - when under load - responds to search queries in the μs range, eats ~30MB RAM and has a low CPU footprint; see our benchmarks).

Tested at Rust version: rustc 1.98.0 (88d9e12ae 2026-08-18)

🇫🇷 Crafted in Nantes, France.

📰 The Sonic project was initially announced in a post on my personal journal.

Sonic

« Sonic » is the mascot of the Sonic project. I drew it to look like a psychedelic hipster hedgehog.

Who uses it?

Crisp logo Scrumpy logo
Crisp Scrumpy

👋 You use Sonic and you want to be listed there? Contact me.

Demo

Sonic is integrated in all Crisp search products on the Crisp platform. It is used to index half a billion objects on a $5/mth 1-vCPU SSD cloud server (as of 2019). Crisp users use it to search in their messages, conversations, contacts, helpdesk articles and more.

You can test Sonic live on: Crisp Helpdesk, and get an idea of the speed and relevance of Sonic search results. You can also test search suggestions from there: start typing at least 2 characters for a word, and get suggested a full word (press the tab key to expand suggestion). Both search and suggestions are powered by Sonic.

Demo on Crisp Helpdesk search

Sonic fuzzy search in helpdesk articles at its best. Lookup for any word or group of terms, get results instantly.

Features

How to use it?

Installation

Sonic is built in Rust. To install it, either download a version from the Sonic releases page, use cargo install or pull the source code from master.

👉 Install from packages:

Sonic provides pre-built packages for Debian-based systems (Debian, Ubuntu, etc.).

Important: Sonic only provides 64 bits packages targeting Debian 12 for now (codename: bookworm). You might still be able to use them on other Debian versions, as well as Ubuntu (although they rely on a specific glibc version that might not be available on older or newer systems).

First, add the Sonic APT repository (eg. for Debian bookworm):

echo "deb [signed-by=/usr/share/keyrings/valeriansaliou_sonic.gpg] https://packagecloud.io/valeriansaliou/sonic/debian/ bookworm main" > /etc/apt/sources.list.d/valeriansaliou_sonic.list
curl -fsSL https://packagecloud.io/valeriansaliou/sonic/gpgkey | gpg --dearmor -o /usr/share/keyrings/valeriansaliou_sonic.gpg
apt-get update

Then, install the Sonic package:

apt-get install sonic

Then, edit the pre-filled Sonic configuration file:

nano /etc/sonic.cfg

Finally, restart Sonic:

service sonic restart

👉 Install from source:

If you pulled the source code from Git, you can build it using cargo:

cargo build --locked --release

You can find the built binaries in the ./target/release directory.

Install build-essential, clang, libclang-dev, libc6-dev, g++ and llvm-dev to be able to compile the required RocksDB dependency.

Note that the following optional features can be enabled upon building Sonic: allocator-jemalloc, tokenizer-chinese and tokenizer-japanese (some might be already enabled by default).

👉 Install from Cargo:

You can install Sonic directly with cargo install:

cargo install sonic-server

Ensure that your $PATH is properly configured to source the Crates binaries, and then run Sonic using the sonic command.

Install build-essential, clang, libclang-dev, libc6-dev, g++ and llvm-dev to be able to compile the required RocksDB dependency.

👉 Install from Docker Hub:

You might find it convenient to run Sonic via Docker. You can find the pre-built Sonic image on Docker Hub as valeriansaliou/sonic.

First, pull the valeriansaliou/sonic image:

docker pull valeriansaliou/sonic:v1.8.1

Then, seed it a configuration file and run it (replace /path/to/your/sonic/config.cfg with the path to your configuration file):

docker run -p 1491:1491 -v /path/to/your/sonic/config.cfg:/etc/sonic/config.toml -v /path/to/your/sonic/store/:/var/lib/sonic/store/ valeriansaliou/sonic:v1.4.9

In the configuration file, ensure that:

Sonic will be reachable from tcp://localhost:1491.

👉 Install from another source (non-official):

Other installation sources are available:

Note that those sources are non-official, meaning that they are not owned nor maintained by the Sonic project owners. The latest Sonic version available on those sources might be outdated, in comparison to the latest version available through the Sonic project.

Configuration

Use the sample config.cfg configuration file and adjust it to your own environment.

If you are looking to fine-tune your configuration, you may read our detailed configuration documentation.

Run Sonic

Sonic can be run as such:

./sonic -c /path/to/config.cfg

Perform searches and manage objects

Both searches and object management (i.e. data ingestion) is handled via the Sonic Channel protocol only. As we want to keep things simple with Sonic (similarly to how Redis does it), Sonic does not offer a HTTP endpoint or similar; connecting via Sonic Channel is the way to go when you need to interact with the Sonic search database.

Sonic distributes official libraries, that let you integrate Sonic to your apps easily. Click on a library below to see library integration documentation and code.

If you are looking for details on the raw Sonic Channel TCP-based protocol, you can read our detailed protocol documentation. It can prove handy if you are looking to code your own Sonic Channel library.

📦 Sonic Channel Libraries

1️⃣ Official Libraries

Sonic distributes official Sonic integration libraries for your programming language (official means that those libraries have been reviewed and validated by a core maintainer):

2️⃣ Community Libraries

You can find below a list of Sonic integrations provided by the community (many thanks to them!):

ℹ️ Cannot find the library for your programming language? Build your own and be referenced here! (contact me)

Which text languages are supported?

Sonic supports a wide range of languages in its lexing system. If a language is not in this list, you will still be able to push this language to the search index, but stop-words will not be eluded, which could lead to lower-quality search results.

The languages supported by the lexing system are:

Only a subset of those languages support stemming. Sonic uses Snowball stemming algorithms via the waken_snowball crate. See the crate’s documentation for a list of supported languages.

How fast & lightweight is it?

Sonic was built for Crisp from the start. As Crisp was growing and indexing more and more search data into a full-text search SQL database, we decided it was time to switch to a proper search backend system. When reviewing Elasticsearch (ELS) and others, we found those were full-featured heavyweight systems that did not scale well with Crisp's freemium-based cost structure.

At the end, we decided to build our own search backend, designed to be simple and lightweight on resources.

You can run function-level benchmarks with the command: cargo bench --features benchmark

👩‍🔬 Benchmark #1

➡️ Scenario

We performed an extract of all messages from the Crisp team used for Crisp own customer support.

We want to import all those messages into a clean Sonic instance, and then perform searches on the index we built. We will measure the time that Sonic spent executing each operation (ie. each PUSH and QUERY commands over Sonic Channel), and group results per 1,000 operations (this outputs a mean time per 1,000 operations).

➡️ Context

Our benchmark is ran on the following computer:

Sonic is compiled as following:

Our dataset is as such:

➡️ Scripts

The scripts we used to perform the benchmark are:

  1. PUSH script: sonic-benchmark_batch-push.js
  2. QUERY script: sonic-benchmark_batch-query.js

⏬ Results

Our findings:

Compared results per operation (on a single object):

We took a sample of 8 results from our batched operations, which produced a total of 1,000 results (1,000,000 items, with 1,000 items batched per measurement report).

This is not very scientific, but it should give you a clear idea of Sonic performances.

Time spent per operation:

Operation Average Best Worst
PUSH 275μs 190μs 363μs
QUERY 880μs 852μs 1ms

Batch PUSH results as seen from our terminal (from initial index of: 0 objects):

Batch PUSH benchmark

Batch QUERY results as seen from our terminal (on index of: 1,000,000 objects):

Batch QUERY benchmark

Limitations

sonic (valeriansaliou/sonic)

Searching Database…

21.4K ·GitHub
这是什么?Sonic 是一个用 Rust 编写的快速、轻量、无需固定数据结构的搜索后端,可以替代 Elasticsearch 这类重量级系统,设计目标是在微秒级内响应搜索请求。
Sonic 是一个我要自己运行的服务,还是嵌进我应用里的库?它是一个独立运行的后端服务器,你通过它自带的轻量 TCP 协议 Sonic Channel 与之通信——它没有 HTTP 接口,README 把这种做法比作 Redis。
我怎么安装和运行它?可以用预构建的 64 位 Debian/Ubuntu 软件包(面向 Debian 12)、cargo install、官方的 valeriansaliou/sonic Docker 镜像,或者从源码构建;然后运行 ./sonic -c /path/to/config.cfg。macOS 上还有一个非官方的 Homebrew formula。
它会像普通搜索引擎那样保存我的文档吗?不会——它索引的是标识符,不是文档:你把搜索文本和对应的 ID 一起推送进去,查询返回的是这些 ID,再由你拿 ID 去自己的数据库里查内容。正因如此它只占用约 30MB 内存。
它能跑在便宜的 VPS 上吗?可以——Crisp 在生产环境中就用它,在一台每月 5 美元、单 vCPU 带 SSD 的云服务器上索引了五亿个对象(截至 2019 年)。
它能处理打错字和自动补全吗?能。如果某个词的精确匹配结果太少,Sonic 会尝试纠正它并搜索其他近义词;此外 suggest 操作可以根据它维护的词图实时自动补全单词。
它能索引哪些人类语言?分词器支持 80 多种使用人数最多的语言(英语、法语、俄语、中文、日语等),会自动猜测语言来剔除停用词。不支持的语言也能索引,只是质量会低一些,而且只有一部分语言能获得 Snowball 词干提取。
我能给我的每个用户单独的搜索索引吗?可以——搜索词存放在按 bucket 组织的 collection 里,平台可以给每个用户分配一个 bucket,让各用户的索引互不干扰。
有适配我所用语言的客户端库吗?官方库有 NodeJS(node-sonic-channel)、Rust(sonicclient)和 PHP(psonic);社区构建的库覆盖 Python、Go、Ruby、Java、.NET、Deno、Bun、Elixir、Crystal、Nim 等更多语言。
Size
4.7 MB
Stars
21.4K
Age
7y
Commits · 90 Days