SabaKore

Home / Articles / AI guides

Running Vector Search on a VPS

How search by meaning works, and how to decide whether you need a dedicated database. It also covers what helps as the number of items grows, the downside of being weak on proper nouns, and how to handle updates to your documents.

Ren, a junior infrastructure engineer

Ren

I often hear about "vector search". How is it different from ordinary search?
Procura, a cloud AI robot who explains

Procura

Ordinary search looks for whether the characters match. Vector search looks for whether the meaning is close. So if you search for "my computer is heavy", you can find a document saying "the PC runs slowly".
Ren, a junior infrastructure engineer

Ren

It finds things even when the words are different!
Procura, a cloud AI robot who explains

Procura

The mechanism is that text is converted by AI into a sequence of numbers in advance, and it looks for the ones whose numbers are close. This sequence of numbers is called a vector.

Do you need a dedicated database?

While the number of items is small, an extension to a database you already use is enough. If you introduce a dedicated one, there's one more thing to run, and you have to look after its updates and backups separately. It's less wasteful to try with the tools you have first and move only when slowness becomes a problem.

Procura, a cloud AI robot who explains

Procura

There are databases dedicated to vector search, but for individuals or small scale you don't need to rush to adopt one. PostgreSQL has an extension that lets you do vector search in the same place as your regular data.
  • Existing PostgreSQL is enough: nothing more to manage, and you can run searches combined with your regular data
  • Where a dedicated database starts to help: when the number of items is very large and search speed matters
  • While it's small, it can even work without a database at all, keeping the data in files

Specs needed on a VPS

Procura, a cloud AI robot who explains

Procura

The search itself is light. What gets heavy is the part that converts text to vectors. If you leave that to an external API, the VPS can stay light, and if you do it with your own model, you need memory.

What helps when the number of items grows

Procura, a cloud AI robot who explains

Procura

With few items, comparing against all of them finishes in an instant. As the number grows, that approach can't keep up. That's where you need a mechanism that builds an index.
  • If search gets slow as the number of items grows, consider building an index
  • An index is a mechanism that chooses "results that are close enough, quickly" over "perfectly accurate results"
  • The more items you have, the more memory you need

The downside of finding things even when words differ

Procura, a cloud AI robot who explains

Procura

Being able to search by meaning is a strength, but it's also a weakness. When you want to find the exact string itself, like a model number or a proper noun, closeness of meaning can miss.
Procura, a cloud AI robot who explains

Procura

That's why combining it with ordinary full-text search is practical. Search with both and mix the results. The trick is not to try to finish with only one of them.

How to handle updates

When you fix the original document, the data for search doesn't follow automatically. If you don't decide on a procedure for rebuilding it, it keeps answering based on old content. And since it looks like it's working normally, you notice late.

Procura, a cloud AI robot who explains

Procura

When you update documents, you need to rebuild those chunks too. If you forget this, old content keeps showing up in search results.
  • Delete the old chunks of an updated document, then create new ones
  • If you change the method used for conversion, you have to rebuild everything
  • Recording which document each chunk was made from makes it easier to manage
Ren, a junior infrastructure engineer

Ren

Try the database I already have first. Use it together with full-text search.

This article is translated from the Japanese original. If the two differ, the Japanese version is the one we keep up to date.