我们将 1.7 TB 数据从 pgvector 迁移到了自研的 Rust 搜索引擎。
We moved 1.7 TB off pgvector to our own Rust search engine

原始链接: https://circleback.ai/blog/moving-meeting-search-off-postgres-and-pgvector

Circleback 在 Postgres/pgvector 变得过慢且不可靠后重建了会议搜索:1.7 TB 未建立索引的向量迫使系统执行全量扫描,拖慢了整个应用;同时,词干提取错误和 CJK 字符丢失导致结果漏检,而嵌入向量又占据了成本大头。搜索需求激增,尤其来自智能体。团队用 Orion 取代了这套方案;Orion 是自研的 Rust 搜索引擎,读取纯文本、自行创建向量,并运行在 Circleback 的云环境中,以保障隐私和控制力。Orion 将不可变索引文件存储在低成本 Blob 存储中,将热点数据缓存在本地/内存中,并在后台压缩整理文件。它还按会议分片,因此查询只打开有权限的分片;权限仍留在应用层。经过大量预览测试,包括内存分配器和 Prisma 的修复,大型账户的片段检索耗时从约 700 毫秒降至 100 毫秒以下,大多数端到端搜索在一秒内完成,Orion 的响应时间只有几十毫秒,漏搜情况变得罕见,成本预计降至约十分之一。

Hacker News 上的一篇帖子链接到 Circleback.ai 的文章《我们将 1.7 TB 数据从 pgvector 迁移到了自研的 Rust 搜索引擎》。讨论区对这项比较持怀疑态度,认为最初的 pgvector 配置优化得很差:它有 1.7 TB 数据,却没有向量索引;文本词干提取的应用也不一致——存储的词被归约为词根,但搜索查询却没有,因此“pricing”不会匹配“price”。一位评论者说,如果与经过合理调优的 Postgres/pgvector 实现进行测量对比,性能比较会更有意义。另一条回复则更尖锐,认为这篇文章无意中承认了严重缺陷,可能未经仔细审阅,而且可能依赖了 AI 生成的内容。
相关文章

原文

Search is at the core of Circleback. Teams use us to record and transcribe their meetings, turning conversations into a shared context layer for both people and AI agents. That context is only useful if search is fast and accurate across every meeting you have access to.

We recently rewrote our search infrastructure from the ground up. On our largest accounts, a search could take up to 40 seconds, and some searches missed meetings they should have found. Now search is instant, finds more of what you're looking for, and costs a fraction of what it did.

Search before and after the move to Orion.Search before and after the move to Orion.

Search in Postgres

Search lived inside our main database, using pgvector. When processing a meeting, we would extract chunks of text from the transcript, generate embeddings, and store those vectors in a massive table. We had 1.7 TB of those and no vector index, so every search scanned the chunks of every meeting you could read. Those scans read from disk and pushed the rest of the app's data out of memory, so the entire app slowed down whenever someone searched. That got worse as search grew: Ask Circleback searches your meetings to answer questions, and agents now search them through our MCP server, API, and CLI. In October we served about 3.5 million searches, 18 times more than in January, and almost 9 in 10 came from agents.

Another issue was our text search strategy, using Postgres' full-text search. When we saved transcripts, we cut words down to their root, so "pricing" became "price". We didn't do the same to searches, so a search for "pricing" never found "price". We also lost characters in Japanese, Chinese, and Korean text. And the embedding service cost us more than any other part of search.

Many companies have a similar architecture, which isn't really an issue until you have to scale it. I joined Circleback about a year and a half ago, and we had to upscale our database at least three times while seeing a steady growth curve, largely because of our inefficient search.

Orion

Why not Turbopuffer or Elasticsearch

A long time ago, back in 2019, I was quite interested in building my own search engine. Orion was used in a few of my projects and had a pretty solid core, but it lacked many of the improvements that other systems, such as Turbopuffer, were bringing. So Claude Opus and I decided to rewrite it entirely, using Rust. It took a weekend to get something working end to end.

Turbopuffer was the obvious alternative, and Orion uses a similar design, so it came down to two things. Turbopuffer stores vectors but doesn't make them, so we'd have kept the embedding service, the part we most wanted to turn off. Orion takes plain text and makes the vectors itself. And Orion runs in our own cloud account, so meeting data never leaves it and we control how it's stored and who can reach it.

Elasticsearch could have done the search, but it keeps its index on disks of machines that run all the time. Most old meetings rarely get searched, and we would rather not pay to keep them all warm.

Cheap storage, fast reads

The main innovation was to keep the index in blob storage, like Google Cloud Storage or S3. Storage there is cheap, but reading from it is slow, so Orion keeps the parts searches need in memory and on a local disk. Files in blob storage can't be changed once they're written. So to save new text, Orion writes a new file, then updates a small file that lists which files are current. It only updates that file if nobody else changed it first, so two writes can't erase each other. After that, the new text shows up in searches. Later, a background job packs the small files into bigger ones that are faster to search.

How Orion saves new text without two writes erasing each other.How Orion saves new text without two writes erasing each other.

Every meeting in its own place

This architecture is quite similar to Turbopuffer. The main difference is that Orion goes further on sharding and isolation. Each meeting has its own section of the index. And Orion splits the index into shards and always puts a meeting in the same one, so a search over a couple of meetings only opens the shards that hold them.

With every search, we tell Orion which meetings it's allowed to read, and it only looks in those. Orion knows nothing about our permissions or access; everything is computed by the application when queried.

A search only opens the shards that hold the meetings you can read.A search only opens the shards that hold the meetings you can read.

Faster, and cheaper to run

Because Orion is more specialized and tailored to our use case, our benchmarks show big gains compared to off-the-shelf alternatives. It also turned out to be much more cost-efficient for us, as we have more control over the machines and what runs on them. The same machines that run Orion also run some microservices for Circleback, thus sharing the cost.

Rolling it out

Fixing leaks

Our first benchmarks were slower than we hoped, but most of that came from bugs and leaks that made Orion look worse than it was. The one I found most interesting: the default Rust allocator held on to freed memory more than we needed, so we switched to jemalloc, which turned out to be significantly more efficient.

Learnings and mistakes

We ran Orion search in a preview deployment next to production, changed one thing at a time and wrote down what each change did. We tried more than 30 changes. Most didn't help. More memory and compressed requests made no difference, and a quantized embedding model was faster but changed the results, so we dropped it.

The worst slowdown turned out to be in our code. Prisma copies binary columns numerous times on their way into Node, which caused long garbage collection pauses with big transcripts.

Rollout

By the end, the preview looked good, and finding the closest chunks for a large account took under 100 ms, down from about 700 ms on the old unindexed scan. So we turned it on for everyone.

A few days later, most searches finished in under a second end to end, and searches that found nothing had become rare. Before the switch, the slowest meeting searches took 20 to 40 seconds. Now Orion itself answers in tens of milliseconds. We've since deleted the old table and turned off the old service, and we expect search to cost about a tenth of what it did.

If you'd like to work on problems like this, we're hiring.

联系我们 contact @ memedata.com