Skip to content

Increase max vectors dimension limit for index #461

Closed

Description

@VincentEggerling

Hello ! I'm wondering what are the reasons for the maximal dimension limit for indexes HNSW and IVFFlat.
Checking really quickly the code, I see those HNSW_MAX_DIM and IVFFLAT_MAX_DIM constants set to 2000 which seem arbitrary to me, as a non-educated user.

  • Why do we have these limits ?
  • How would performance scale if the limited were, say, doubled ?
  • Is there a plan to increase the limits, considering other vector database products offer up to 32768 dimensions (or even more) for indexed vector ?

Thank you !

Activity

  1. jkatz commented on Feb 16, 2024

    @jkatz
    Contributor

    @VincentEggerling

    Why do we have these limits ?

    There's been quite a bit of discussion on this topic -- the primary limitation is due to the default size of the PostgreSQL page (8KB), which is not adjustable, which constrains the number of 4-byte floats you can store on a page. There are some branches that address this (e.g. the tiny and half branch) that lets you store vectors with more dimensions but a smaller attribute value. There's also an open idea on implementing quantization, particularly product quantization (#27).

    How would performance scale if the limited were, say, doubled ?

    Just increasing the limit would not decrease performance 😉 For storing and searching over vectors with more dimensions, it depends on a variety of factors, including the size of the dimensions or if any additional storage techniques are used.

    Is there a plan to increase the limits, considering other vector database products offer up to 32768 dimensions (or even more) for indexed vector

    Yes, but part of that will drive that is understanding what use cases require that increase, and the different tradeoffs that come with increasing the indexable dimensionality.

  2. kevintanhongann commented on Mar 4, 2024

    @kevintanhongann

    I wish it can be increased to 4096 or more than that, based on what i have tested. No matter when it's the string of question answer pairs or even an extracted text from the a PDF document. I was mentioning BRIN or GIN before, but that was just based on the result of researching using Microsoft Copilot. Do let me know if there is a way to workaround this. Thanks.

  3. HectorBst commented on Mar 8, 2024

    @HectorBst

    It would be very interesting to be able to increase this limit beyond 2000. The new mistral-derivative embedding models (4096 dims) and OpenAI’s new text-embedding-3-large model (3072 dims) offer very good performances, but are not yet compatible with pgvector. We're likely to see more and more good models with an increasing number of dimensions.

  4. yashukla47 commented on Mar 8, 2024

    @yashukla47

    Yes, we are also using a text-embedding-3-large model (3072 dims) and it'll be really helpful if the limit is increased to somewhere around 3072 or 4096. @jkatz what do you think by when can we expect it ?

  5. brpy commented on Mar 9, 2024

    @brpy

    This would enable us to use newer OpenAI embedding models, that support upto (3072 dims).

    The newer models seems to outperform the older ada002 embedding model, even with compressed to 256 dims. This feature would enable us to try out the newer model with full dimensions on postgres.

    Thank you!

  6. GPF199541 commented on Mar 13, 2024

    @GPF199541

    +1

  7. AnonymousBoy commented on Mar 18, 2024

    @AnonymousBoy

    pgvecto.rs could support up to 65535 dimensions, could pgvector also support it?

    https://github.com/tensorchord/pgvecto.rs

  8. jkatz commented on Mar 18, 2024

    @jkatz
    Contributor

    pgvecto.rs could support up to 65535 dimensions, could pgvector also support it?

    Are there examples of use cases with vectors of that high dimensionality that are being used with vector databases? I know there are some cases in the "up to 4,096 dimension" range (such as the cited ada003 model above), but I'm curious what is being used beyond that.

    Unless something has changed since I last checked, pgvecto.rs bypasses the PostgreSQL storage system, which makes it easier to index vectors that are larger than 8KB, with the tradeoff that you're losing ACID (especially the "D") guarantees. Based on what you're doing with your application, that may be an acceptable tradeoff and allows you to index larger vectors in PostgreSQL today, though I'd advise that the PostgreSQL storage system provides a lot of infrastructure around data management that's easy to take for granted (and I certainly have while going on this vector journey!).

  9. shao-shuai commented on Mar 29, 2024

    @shao-shuai
    image some of the latest embedding models have dimension over 2000, if we can increase the limit to at least 4096, that would be super helpful to get pgvector involved in the development and test of embedding models. https://huggingface.co/spaces/mteb/leaderboard
  10. jkatz commented on Mar 29, 2024

    @jkatz
    Contributor

    Per #326 (comment) and #395 (comment) there are now proposed patches that would allow for the increasing of max dimension.

  11. wmwsagara commented on Mar 30, 2024

    @wmwsagara

    TL;DR:
    This is a proposal for pgvector to support lot more than 2000 fp32 vector dimensions without modifying PostgreSQL or lower the accuracy of vector embeddings.

    It is not possible to support more than 2000 vector dimensions! See @jkatz first post: "the primary limitation is due to the default size of the PostgreSQL page (8KB), which is not adjustable ...".

    8K, 8192/4 = 2048.
    floating point 32bit (fp32) or float is 4 bytes.
    Max dimensions: 2000
    Allocation for Overhead: 48

    There are 3 solutions available:

    1. Modify PostgreSQL
      Ask the PostgreSQL developers to offer an option configure PostgreSQL page size at PostgreSQL server start time. This has the possible negative consequences for PostgreSQL IO pipeline. It's may be too risky and may require extensive testing. Therefore, to the most probability, PostgreSQL developers may turn down this request, or may take quite long to get developed.

    2. Go for lower accuracy
      fp16:
      8000/2 = 4000
      Max dimensions: 4000
      Still 4096 dimensions cannot support!
      Require to go even lower accuracy to support 4096. How about 8K dimensions? It might hit 8K by next year.

    There can be some application domains lowering accuracy may be bearable. There can be domains, cannot risk to lower the accuracy.

    3. Proposal - split the document table

    Text part is in the document table, embeddings are in a separate embedding table. There may be one or more records in the embedding table for a one document, each embedding record support up to max 2000 dimensions.

    The document table record layout:
    document_reference - string
    content - text

    The embedding table record layout:
    document_reference - string
    seq_no - number
    embedding [] - array

    Indexed by: document_reference+seq_no

    To support 3072 dimensions, you need two (2) records in the embedding table.
    To support 4096 dimensions, you need three (3) records in the embedding table.

    When build the index (eg. HNSW), read all embedding records for a document and reconstruct the original dimensions required (eg. 4096) for the document just by append them sequentially. Rest are all in memory operations.

    To build the index, pgvector has to read only the embedding table in document_reference+seq_no order.

    The document_reference can be a UUID or any other string.

    Advantageous:
    a) No need to modify PostgreSQL.
    b) Fully ACID compliant.
    c) No maximum limit for number of fp32 vector dimensions can be supported.
    d) Straight away can be implemented without depending on any third party.

    disadvantageous:
    a) Require to restructure pgvector.

    I think, it is possible to offer a hybrid version. That is, no change to user's code up to 2000 dimensions. That is, text and embedding can reside in one table record.

    But if the user require more than 2000 dimensions, all embeddings are read from embedding table.

    Best regards
    Sagara

  12. KnightMurloc commented on Mar 30, 2024

    @KnightMurloc

    Modify PostgreSQL

    The size of Postgres pages can be increased via the compilation parameter (--with-blocksize) up to 32 KB. Which should allow to create vectors up to 8192 dim.

  13. wmwsagara commented on Mar 30, 2024

    @wmwsagara

    Thank you @KnightMurloc for the insight.

    The --with-blocksize is defined here: https://www.postgresql.org/docs/16/install-make.html

    I think @jkatz is a PostgreSQL developer, I'm not. @jkatz could you enlighten us why the --with-blocksize cannot be used?

  14. jkatz commented on Mar 30, 2024

    @jkatz
    Contributor

    @wmwsagara For your proposals, if we look at the tests in #326 (comment) we see that the fp16 quantization proposal that allows for increasing dims to 4,000 has almost no impact on recall.

    While the PostgreSQL table ("heap") block size is adjustable, the index block size isn't. This thread outlines where the restriction is, and the effort it'd take to adjust.

    At PGConf.dev 2024, I'm planning to discuss this topic and some proposals to better address this upstream.

    "Proposal 3" is somewhat similar to HOT chaining, which I lightly discussed in 2023. While this would allow for storing larger dimensions, it itself has tradeoffs as index lookups require fetching multiple pages per comparison. We would likely want some methodology where we could fetch pages in parallel, but the overhead of that could be too much at the moment and requires more research.

  15. wmwsagara commented on Mar 31, 2024

    @wmwsagara

    @jkatz
    Wish you good luck for your lecture at the PGConf.dev 2024. Hopefully it may leads to development of an acceptable solution this issue. Please try to video record your presentation and release on YouTube, so that we all can see it.

  16. 30 remaining items

  17. jkatz commented on Nov 11, 2024

    @jkatz
    Contributor

    I think there are a few things - first, that comparison chart linked above is not accurate as of this writing, and I'd state things a little differently.

    "WAL support" is directly tied to durability (the D of ACID), meaning that if a transaction is committed, the data is guaranteed to be stored regardless of a system failure. That's a very powerful (if not the most important) guarantee when working with data in a database. As the pgvecto.rs authors demonstrate, there's write-overhead to using that, but that's up to you to decide on what tradeoffs are more important (e.g. I need to store higher dimensional vectors and understand the risks associated to bypassing the PostgreSQL durability mechanism - there are cases where that tradeoff is acceptable). I haven't looked at pgvecto.rs in depth in awhile, so I'm not sure what other ACID tradeoffs there are.

    I don't really want to do a "this-or-that" comparison between the two projects, but I'll clarify a few points related to pgvector:

    • Filtering - pgvector v0.8.0 changed a lot around filtering (I'll personally be writing / presenting more about this topic int he coming weeks), and now has the appropriate mechanisms to avoid the "overfiltering" problem.
    • SIMD - pgvector has supported SIMD through compilation since at least I started with the project almost 2 years ago, primarily through the use of autovectorization and other compiler flags. The v0.7.0 work was on explicit dispatching for x86-64 architecture, but SIMD was already supported
    • Data types - pgvector introduced vector, halfvec (fp16), and sparsevec, and leverages the upstream data type binary vectors (bit). There are branches open for a few others (intvec, minivec), with supported dependent on a variety factors (such as your use cases!)

    So this comes into the question at hand - what about maximizing limits? Today, while you can use, for example, a cast from vector to halfvec, yes that can certainly lose information as part of the search and return less than ideal results. However, to understand the best path forward, where it's an existing solution for further development, it'd help to unpack this:

    This dimension limitation is a critical blocker that prevents our organization from using pgvector, forcing us to maintain a separate vector database instead of leveraging our existing PostgreSQL infrastructure. We've evaluated the proposed workarounds like halfvec and quantization, but the reduction in accuracy is unacceptable for our use case. The ability to index higher-dimensional vectors (3072+ dimensions) while maintaining full precision would be transformative for our ability to consolidate on PostgreSQL.

    @orentet For example, what is your recall target? What are you currently achieving? How much data are you storing in your index? What does your schema look like? What query patterns do you have? Are you doing any reranking (e.g. searching over the halfvec index, then doing a final reordering on the full vector in the table?). Do you have any filters on the data? Understanding details helps to guide what next steps may be.

    That said, at PGConf.eu 2024 I had a long discussion with one of the PostgreSQL committers around expanding the buffer/page size for indexes and potential paths forward. First, this would be a very big project (at least what we were discussing), and, at least as discussed, it would create additional configurations on the PostgreSQL side to support embeddings that go past 8KB. But, it would allow for continuance of relying on PostgreSQL storage mechanisms (e.g. durability) for these larger vector types.

    Additionally, there may be ways shorter term to achieve storing larger vectors (e.g. page chaining), but that could potentially lead to performance crunches that may make it unsuitable, but it's likely worth the experiment to try.

  18. rohitghatol commented on Nov 29, 2024

    @rohitghatol

    Let’s say I have a dimension limit of 6000 for example but I use a sparse vector with say 20 non zero values at most.

    “Does the 2,000-dimension limit for indexing in pgvector apply to sparse vectors as well, or is the limit determined by the number of non-zero elements in the sparse vector?”

  19. jjanczur commented on Dec 12, 2024

    @jjanczur

    Is there any update on this matter? Native support for 3k (or preferably 4k) dimensions in pgvector would be a game-changer. It would eliminate the need for hacky workarounds that compromise accuracy or the overall quality of search results. I completely agree with @orentet on this point - other workarounds are unacceptable for us too and we have to use other dbs.

    In our case, we’ve observed a significant improvement in handling multilingual documents when using models with dimensions greater than 3k (OpenAI large and Mistral with 4k dimensions)

  20. jkatz commented on Dec 12, 2024

    @jkatz
    Contributor

    In our case, we’ve observed a significant improvement

    Can you please define what "significant improvement" means here? Do you have any recall or other measurements to show how much this increased?

  21. jjanczur commented on Dec 12, 2024

    @jjanczur

    Hi, sure!

    We began by reviewing results from well known benchmarks such as MTEB and MIRACL and their results.

    Following this, we conducted an internal evaluation using our own dataset. This involved testing various embedding models and experimenting with different chunk sizes and overlaps, primarily on German, Dutch, and French legal texts, including court decisions and patents.
    (We had mainly German court decisions and contracts in German and Dutch)

    Our initial focus was on optimizing the chunk size and overlap settings to suit our specific use case.

    We designed tests using texts, questions and pre-identified chunks. These texts were complex, with questions heavily relying on intricate legal nuances. While we experimented with metrics like NDCG@10 and MAP@10, consolidating the results into meaningful insights was more challenging than anticipated. 😅

    Ultimately, we applied RAGAS benchmarks to a similar set of test questions and answers within a standard RAG setup.

    Although I don’t recall the precise metrics, higher-dimensional models consistently outperformed others on this type of complex documents. For our use case, even a 20% performance improvement was significant, and as I recall, the results exceeded that threshold. (At least in our internal test, on our internal data, that was close to the production use case)

  22. ankane commented on Dec 12, 2024

    @ankane
    Member

    Can you share more about why half-precision indexing (for vectors up to 4k dimensions) or binary quantization with re-ranking (for larger vectors) isn't sufficient for this (including the recall numbers, index build options, and search options)?

  23. jjanczur commented on Dec 12, 2024

    @jjanczur

    We ended up with reranking being absolutely best solution - qualitywise + pinecone where we could just keep full embedding. We could do there as well namespace search and metadata filtering which was crucial for the usecase.

    I don’t like pinecone because they are closed source but they are easy to use and have absolutely fantastic docs. We evaluated a few other solutions as well.

    As I mentioned we wanted to use pgvector but ended up with pinecone never tested the impact of 2000 out of 3k dimensions mostly because of the 2k restriction.

    edit: 2k out of 3k i have in mind not truncating the vector ofc. But just using larger model with less dimensions.

  24. jjanczur commented on Dec 12, 2024

    @jjanczur

    For solutions where speed and low latency are critical reranking adds yet another part that just takes time

  25. markthepixel commented on Feb 1, 2025

    @markthepixel

    It would seem this has all but been resolved?

  26. FaediMichele commented on Feb 24, 2025

    @FaediMichele

    I'm using a workaround for cosine distance.
    You can split the vector in two half and simply order by the sum the dot product between the two vectors.
    This works only if the vectors are normed (the full vector, not the half) before storing and querying.
    Remember to change the index for dot product.

    Don't know much about efficiency though

  27. ankane commented on Feb 25, 2025

    @ankane
    Member

    This was largely addressed with 0.7.0 (released at the end of April 2024), which added the ability to index up to 4,000 dimensions with the halfvec type and 64,000 dimensions with the bit type.

    If there are situations where someone is seeing significantly worse recall with half-precision indexing or binary quantization with re-ranking, please create a new issue with the details.

  28. BobLamarley commented on Mar 26, 2025

    @BobLamarley

    Hello everyone,
    Sorry for being the nooby of this thread:
    I'm currently facing this error : "index row requires 12304 bytes, maximum size is 8191" because i'm trying to store an embedding of 3072 dimensions coming from text-embedding-3-large of OpenAI
    From what i've read, the only solutions at this moment are:

    • switch to text-embedding-3-small ?
    • stay with text-embedding-3-large but use max_dimensions parameters to 1536 ?

    Which is preconised ?

    There's no tricks to store a 3072 dimension vector as of now ?

    Thanks

  29. ankane commented on Mar 26, 2025

    @ankane
    Member

    It sounds like you're using either a modified version of pgvector or a different extension (pgvector should show a different error message). Please avoid commenting on long, closed threads to avoid notifying everyone.

  30. locked and limited conversation to collaborators on Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions