pg.ddx.io  pgvector/pgvector GitHub issues and pull requests  
help / color / mirror / Atom feed
From: jkatz (@jkatz) <noreply+jkatz@github.com>
To: pgvector/pgvector <noreply+pgvector-pgvector@github.com>
Subject: Re: [pgvector/pgvector] issue #666: search too slow when I clean the cache
Date: Thu, 05 Sep 2024 13:22:40 +0000
Message-ID: <gh-pgvector-pgvector-666-c2331673610@github.com> (raw)
In-Reply-To: <gh-pgvector-pgvector-666@github.com>
References: <gh-pgvector-pgvector-666@github.com>

> So I guess pg loads the index from disk into the cache to improve search speed.

This is typically a standard practice with databases, as it's faster to read data from memory than disk. You can control the overall amount of memory that's maintained in PostgreSQL using the `shared_buffers` parameter; PostgreSQL uses a memory management algorithm to determine what pages (atomic units of data) are evicted that is based on frequency of access and usage, though even a frequently accessed page could be evicted if you're pulling a large dataset into memory.

To your specific questions:

> Reduce the size of the index, such as using halfvec consine ops or binary quantization to build the index. I have tried this method, and the index is indeed much smaller. Without cache, it is indeed much faster than vector consine ops, but It takes 30 seconds at the fastest, and the recall of binary quantization is very low.

If you're using binary quantization, you'll [likely need to use a re-ranking technique](https://jkatz05.com/post/postgres/pgvector-scalar-binary-quantization/) to boost recall.

> Is there a way to keep the loaded cache from being preempted by other applications?
> Warmup, I have used the following configuration to warmup, and it is indeed effective, but it cannot completely warmup to 100ms search time, and there is still a situation where the cache is preempted by other applications.

Not directly. Presenting two options that are on the simpler side: (1) increase the size of available memory in your environment, so you can increase `shared_buffers` and have more memory available; (2) add a replica to your system and direct other queries there (likely your vector search queries). You could also break out the vector workload to its own instance or independent database (not a logical database in `CREATE DATABASE`), so it has its own memory pool where it's not competing with resources from other applications.

view thread (8+ messages)  latest in thread

Message-ID: <gh-pgvector-pgvector-666-c2331673610@github.com>
Permalink:  ../gh-pgvector-pgvector-666-c2331673610@github.com/

 · 


This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox