Are we at peak vector database?
softwaredoug.com
softwaredoug.com
I think there's space for a much more interesting product that is longer-lived (since it's harder to implement than just cosine-similarity-search on vectors), which is:
1. Fine-tuning OSS embedding models on your real-world query patterns
2. Storing and recomputing embeddings for your data as you update the fine-tuned models.
MTEB averages are fine, but hardly anyone uses the average result: most use cases are specialized (i.e. classification vs clustering vs retrieval). The best models try to be decent at all of those, but I'd bet that finetuning on a specific use case would beat a general-purpose model, especially on your own dataset (your retrieval is probably meaningfully different than someone else's: code retrieval vs document Q&A, for example). And your queries are usually specialized! People using embeddings for RAG are generally not also trying to use the same embeddings for clustering or classification; and the reverse is true too (your recommendation system is likely different than your search system).
And if you're fine-tuning new models regularly, you need storage + management, since you'll need to recompute the embeddings every time you deploy a new model.
I would pay for a service that made (1) and (2) easy.
(easy to extend to two layers mlp as needed. maybe ensure that x and y are zero mean and unit length to make training the matmul a bit easier.)
Also, a member on our team developed an amazing RNN-based model that still today beats the pants off most embedding models when it comes to speed, and is no slouch on CPU either…
(* I'm being harsh on BM25 - it is a baseline that people often forget in vector search, but it can be a tough one to beat at times)
When the time is finally right, people just "invent" what you made all over again.
I know nothing about search, but a bit about ML, so I'm curious
This is not as easy as you make it sound :) Typically, the embeddings are multi-modal: the query string maps to a relevant document that I want to add as context to my prompt. If i collect lots of new query strings, i need to know the ground truth "relevant document" it maps to. Then I can use the two-tower embedding model to learn the "correct" document/context for a query.
I have thought about this problem for LLMs that do function calling. And what you can do is collect query strings and the function calling results, and ask GPT-4 - "is this a 'good' answer?". GPT-4 can be a teacher model for collecting training data for my two-tower embedding model.
Reference: https://www.hopsworks.ai/dictionary/two-tower-embedding-mode...
Peak "$XXXXXXXX" database is when your particular flavor of DB is completely consumed into traditional RDBMSes.
Vector databases (and all other incremental or transformational improvements) are just features of regular plain traditional RDBMSes that have not been implemented in traditional RDBMSes yet.
I have seen every new DB tech subsumed by traditional databases over time as compute capability improved.
No exceptions.
The list is endless:
- object databases (e.g. blobs, JSON)
- OLAP
- in DB programming ( XX-SQL eg PL/SQL, T-SQL, ANSI-SQL)
- column-oriented data stores
- key-value
- graph databases
- No SQL
- Cloud, distributed, whatever
- statistical analysis databases
- document databases
All these used to be standalone, very expensive, specialty products but are now just one more checkbox on the Oracles/SQL-Servers/DB2s of this world.
All these have been swallowed by the borg of commercial databases without so much as a burp.
There is no winning the commercial market long term for these products. Big business buys traditional RDBMSes because they are the kitchen sink. They do EVERYTHING and they will eventually do this new hot thing, the business will just have to pay big dollars for it. Which is not a problem for big business.
There is a reason that cartoon about the Oracle org hierarchy was made (bottom right): all the company does is make product (Engineering) and protect that product. And it is very good at making good product.
https://i0.wp.com/stratechery.com/wp-content/uploads/2013/07...
There is a YC startup, latnern, that also built their own extension for postgres that is open source and is better for vector DB use cases: https://github.com/lanterndata/lantern
But yeah! Traditional DBs already support this, if you consider this extension to be part of Postgres.
When Pinecone came out and started blogging heavily it seemed that they'd read the same papers I did but came to the conclusion the glass was half full instead of half empty. I could have missed it but I haven't see anything in the literature that's a huge improvement over 20 year old algos.
Circa 2014 I worked on a search engine for patents and related literature that made vectors for 20 million + documents and they decided to use full scan and (i) it performed so well (in terms of accuracy) that we sold a license to the USPTO on day two after we put up the demo, and (ii) there were a lot of things about it that were slow like the build system, index building and model training but vector search wasn't one of them.
My YOShInOn RSS reader has about a million documents in 2024 and it uses vectors for classification and clustering. Using vectors for search is a clear extension and I've done some prototyping of searches with full-scan and performance is "good enough" (full scan has 'mechanical sympathy'.) I'd probably stuff my vectors into FAISS if I wanted to do anything more and forget about it.
Sending my vectors to some cloud service so they can pay AWS prices to store them? That's for the birds. I respect Pinecone for being early to the party but I think those who jumped in in 2022 were laggards.
I'm not sure if that makes me more or less qualified to do vector DB's -- I tend to block out things that I learned a lot about in the past without much result.
While traditional database indexing is also still an open-ended research problem (e.g., read amplification/write amplification tradeoffs and the like), it produces exact solutions. That isn't the case at all for vector indexing beyond brute-force search, or exact indexing like k-D/BSP trees which don't work well in high dimensions due to the curse of dimensionality.
For Euclidean (L2) distance indexes where the vectors are partitioned based on geometry (e.g., pretty much every indexing type, including cell-probe like IVF, most forms of LSH, or graph based indices), query vectors can be naturally associated geometrically with candidate nearest neighbor vectors, so the distribution of queries doesn't matter as much.
For inner product, it's hard to do much better than spherical clustering (what one would usually do for cosine similarity, which is to project all vectors to the surface of a unit hypersphere, and searching for nearest neighbors via cosine similarity is exactly equivalent to L2 search). But, in general the maximum inner product in the indexed set may lie nowhere near to the projection of the query vector onto the surface of the hypersphere.
The maximum inner product for a query vector might be almost nearly perpendicular to the query vector (e.g., a very, very far out and almost perpendicular) versus a vector that is parallel to the query vector but with tiny norm. In two dimensions, an example could be (1, 0) as a query vector, but (1, 10^6) as a database vector (or vice versa). The inner product is 1 but the two vectors are very far apart in Euclidean distance. If you project the vectors to the unit 1-sphere, the query vector is still (1, 0) but the database vector now becomes (1 / sqrt(10^12 + 1), 10^6 / sqrt(10^12 + 1)) ~= (0.000000999..., 0.99999...) (apologies if there's an error here) which would also be in a very different cell if one were using a graph-based or IVF partitioning.
Neural search techniques do show some promise here though (say, using a neural net to predict which vector buckets to look at).
What kinds of use cases cause this kind of situation, where the query and indexed vectors are from different distributions?
I think what I mean to say is that, in my experience, practitioners and vendors alike are overly focused on "just put embeddings somewhere and do cosine similarity" and that's the only problem to solve. In fact, that's a teeny tiny part of it. Hence "peak vector DB".
So I think the market needs some education that its harder than that. That part is my rant :). I've spoken / worked on enough problems now to see that disconnect between market and reality.
Though I think "vector DB" is actually a place for capital/brainpower to concentrate to solve these other problems. And I think we'll see the vector DB vendors pivot there. It's just taking a while for the market and investors to see this...
I agree, and as one who does exactly and only this on the search side, it's also something that falls flat on its face if you don't think a little more about the data and tasks involved.
I wrote about it here[0], but the gist of it for our use case is that if we don't intentionally include what may be considered "less relevant" data then we stand a good chance at failing our main generative task.
[0]: https://phillipcarter.dev/2024/01/15/three-properties-of-dat...
In general you can see the raw text as a simulation premise that will generate inferences when "executed". The inferenced part is like the hidden part of the iceberg, you don't see it but it is there, implicit in the source text. Not just in math, but in all fields.
Embeddings are only good at superficial retrieval. The text needs to be fully analyzed with LLMs before embedding. Thus my conclusion is that we still have a long way to go, we haven't peaked.
It’s a pretty simple thing to add to a pipeline. Have you tried?
I am currently testing embeddings/RAG and could use some insight on how to make the results better.
If you happen to know what kinds of questions you will be asking about your RAG index, you should pre-process the texts to add QA pairs. Otherwise you can prompt the LLM to do chain-of-thought inferences based on the source text and add them to the material.
I guess you put put a whole doc into the I’ll and ask what questions it answers?
And then use those question plus a piece of the text and do an embedding?
Also, you are probably doing it wrong by turning a matrix to matrix multiplication into a for loop (over rows). The optimal solution results in better performance
sim = np.vstack(df.col) @ vec
The one I'm working on right now has 115K docs (some quite big - I'll likely have to prune the largest 10% just to fit in my RAM).
These are all "small" - for personal use on my local machine. I'm currently RAM limited, otherwise I can think of (personal) use cases that are an order of magnitude larger.
Of course, for all I know, your method may still be as fast on those as on a vector DB.
Going further down the AI == compression path, there’s: http://prize.hutter1.net/
Always felt they're more like hashes/fingerprints for the RAG use cases.
> Typically documents are broken down into chunks
That's what I would have guessed. It's still surprising that the embeddings don't fit into RAM though.
That said (the following I just realized), even if the embeddings don't fit into RAM at the same time, you really don't need to load them all into RAM if you're just performing a linear scan and doing cosine similarity on each of them. Sure it may be slow to load tens of GB of embedding info... but at this rate I'd be wondering what kind of textual data one could feasibly have that goes into the terrabyte range. (Also, generating that many embedding requires a lot of compute!)
Yes, I see where you’re coming from. Perceptual hashes[0] are pretty similar, the key is that similar documents should have similar embeddings (unlike cryptographic hashes, where a single bit flip should produce a completely different hash).
Nice embeddings encode information spatially, a classic example of embedding arithmetic is: king - man + woman = queen[1]. “Concept Sliders” is a cool application of this to image generation [2].
Personally I’ve not had _too_ much trouble with running out of RAM due to embeddings themselves, but I did spend a fair amount of time last week profiling memory usage to make sure I didn’t run out in prod, so it is on my mind!
[0] https://en.m.wikipedia.org/wiki/Perceptual_hashing
[1] https://www.technologyreview.com/2015/09/17/166211/king-man-...
Each vector is 1536 numbers. I don't know how many bits per number, but I'll assume 64 bits (8 bytes). So total size is 1536 * 115K * 8 / 1024^2 gives 1.3GB.
So yes, not a lot.
I still haven't set it up so I don't know how much space it really will take, but my 40K doc one took 2-3 GB of RAM. It's not pandas DF, but in an in-memory DB so perhaps there's a lot of overhead per row? I haven't debugged.
To be clear, I'm totally fine with your approach if it works. I have very limited time so I was using txtai instead of rolling my own - it's nice to get a RAG up and running in just a few lines of code. But for sure, if the overhead of txtai is really that significant, I'll need to switch to pure pandas.
You'll realize that it scales well beyond 1k.
The problem is what happens when you have an additional 6 orders of magnitude of data, and the data itself is significantly larger than the system RAM, which is a very realistic case in a search engine.
Here's some back of the envelope math. Let's say you are using a 1B parameter LLM to generate the embedding. That's 2B FLOPs per token. Let's assume a modest chunk size, 2K tokens. That's 4 trillion FLOPs for one embedding.
What about the dot product in the cosine similarity? Let's assume an embedding dim of 384. That's 2 * 384 = 768.
So 4 trillion ops for the embedding vs 768 for the cosine similarity. That's a factor of about 1 billion.
So you could have a billion embeddings - brute forced - before the lookup became more expensive than generating the embedding.
What does that mean at the application level? It means that the time needed to generate millions of embeddings is measured in GPU weeks.
The time needed to lookup an embedding using an approximate nearest neighbors algorithm from millions of embeddings is measured in milliseconds.
The game changed when we switched from word2vec to LLMs to generate embeddings.
1 billion times is such a big difference that it breaks the assumptions earlier systems were designed under.
The embedding is generated once. Search is done whenever a user inputs a query. The cosine similarity is also not done on a single embedding, it's done on millions or billions of embeddings if you are not using an index. So what the actual conclusion is, is that once you have a billion embeddings a single search operation costs as much as generating an embedding.
But then, you are not even taking into account the massive cost of keeping all of these embeddings in memory ready to be searched.
Another one is where the data is sliced based on a key, eg user id, particular document being worked on right now, etc
This issue is prevalent throughout infrastructure projects. Someone decides they need a RAG system and then the team says "let's find a vector db provider!" before they've proven value or understood how much data they have or anything. So they waste a bunch of time and money before they even know if the project is likely to work.
It's just like the old model of setting up a hadoop cluster as a first step to do "big data analytics" on what turns out to be 5GB of data that you could fit in a dataframe or process with awk https://adamdrake.com/command-line-tools-can-be-235x-faster-... (edit: actually currently on the HN front page)
It's a perfedt storm of sales led tooling where leadership is sold something they don't understand, over-engineering, and trying to apply waterfall project management to "AI" projects that have lots of uncertainty and need a re-risking based project approach where you show that it's liable to work and iterate instead of building a big foundation first.
These days anything less than 2TB should be done 100% in memory.
You might be interested in SearchArray which emulates the classic search index side of things in a pandas dataframe column
Not sure if others have gone down this path but I have been testing out ways to store vectors to disk in files for later retrieval and then doing everything in memory. For me the tradeoff of a sligtly slower response time was worth it compared to the 4-5 figure bill I would be getting from a vector DB otherwise.
Cosine similarity measures the angle between two vectors instead, and doesn't suffer from the curse of dimensionality.
I guess it's important to have this in your DB, so you make "nearby" queries (give me text that's similar to this other text) in an efficient way.
Did it? After using Mongo in my current job (not my choice), I'd choose Postgres again for my next project.
This is already the case. Recommendations are just a fancy search where the query is a vector representing the user. Whether the learning is batched or not doesn't change the fact that it will use vector search for at least candidate generation.
There is still plenty of room for innovation in this space. Just need to focus on the right projects that are innovating and not the ones (re)working on problems solved in 2020/2021.
And here's a post on an alternative way to integrate vectors with traditional databases (Postgres, MySQL) - https://neuml.hashnode.dev/external-database-integration
As others have said in this thread, cosine similarity on arrays of vectors isn't novel. But there are many possibilities past that, many we haven't thought of yet too.
(I'm an investor so I'm biased; but it's also the reason why I invested)
Why bother with chunking data, synching it, and then tagging metadata to it. DB providers should be smart enough to optimize chunking strategy for the kind of content being indexed and then provide a simple API endpoint to query against their data.
"RAG in a can".
If there is, what api differentiates it, and why can’t this be expressed in either elasticsearch or Postgres?
Then on the other side existing databases will want to add functionality to be used as vector databases as well.
I think there’s lots of innovation ahead and it’s too soon to know what the end outcome will be.
Same with languages.
Why so many languages.
Why can't we all get behind a few, do we need more than 6? For every case/problem? Put all our combined resources towards a smaller set.
We need a few DB's, a few languages, a few frameworks. Do we need hundreds?
Like everyone rolls their own everything.
Cassandra and Scylla are row based distributed key value stores.
I know it's subjective, but databases have started to feel like running a window manager and desktop on a server.
I feel like software needs to take a step back and rethink itself after years of putting chimps at typewriters searching for Shakespeare.
Why not a Linux kernel with a module(s) to provide the same assurances, SQL operations? Write directly to the filesystem?
Why is all the mathematical concept that we derive software from packaged into endless conceptual blobs of black box state?
https://www.reuters.com/technology/openai-annualized-revenue...
The same principle applies to defense. The US gives Israel and Ukraine tens of billions, but that’s a credit to buy from US defense firms. That money gets recycled right back to US weaponry.
But in the Microsoft example it is customers who are paying Microsoft to use OpenAI via Azure. Thats a free market of money inflows. Same with all the people using OpenAI directly. Not sure how you would even think of the money being recycled in this scenario. Yes of course there is some back scratching in the sense that Microsoft invested in OpenAI with a large portion of that investment in Azure credits which makes the investment quite nice from MSFT's side but there is still real demand for Azure services to use OpenAI apis.
This is obvious, but if you need some journalist to validate what is already logically clear:
https://www.wsj.com/tech/ai/ais-costly-buildup-could-make-ea...
https://www.wsj.com/tech/ai/ai-deals-microsoft-google-amazon...
You are really conflating too many things at once.
1) Yes, big tech is having a hard time monetizing their bespoke AI tooling within their own ecosystem.
2) Yes, big tech has made investments in the AI space where they are providing a portion of that funding as credits to use in their cloud offerings.
3) Here is where you are incorrect though. Companies are writing large checks for the raw compute/access to AI models. It is true across the spectrum of Azure OpenAI, OpenAI directly, AWS Bedrock etc, there are a lot of companies both big and small using these services heavily. To think otherwise is naive.
- Vectors are massive data wise. In our current production database they take up 95% of the memory - should they be stored separately?
- Better support for easily re-embedding, hybrid search, certain RAG workflows
- Stronger performance once you're dealing with millions of vectors.
I would still stick with PgVector until you're dealing with non trivial scale.
There are ways to speed things up dramatically. Index build just became multithreaded (see above).
We have ideas on what to do with ingest.
Also do you interest from S3 ?
https://github.com/pgvector/pgvector/issues/409#issuecomment...
But if Postgres wins we all win!
The closest I can see is the VSS extension[1] for Sqlite.
Context: I'm working on an e2ee alternative to Google Photos[1] where we have to cluster embeddings (for face recognition) and run similarity searches (for semantic search[2]) on device.
[1]: https://ente.io