Live data from Hacker News

The best way to use text embeddings portably is with Parquet and Polars

minimaxir.com

41–50 of 61 posts

Re: The best way to use text embeddings portably is with Parquet and Polars

#41
post #40

I still don't like dataframes but oh my God Polars is so much better than pandas. I was doing some time series calculations, simple equity price adjustments basically, in Polars and my two thoughts were: - WTF, I can actually read the code and test it. - it's running so fast it seems like it's broken.

There’s some nice plugins too, some are finance related: https://github.com/ddotta/awesome-polars

Re: The best way to use text embeddings portably is with Parquet and Polars

#42
post #25

Really cool article, I've enjoyed your work for a long time. You might add a note for those jumping into a sqlite implementation, that duckdb reads parquet and launched a few vector similarity functions which cover this use-case perfectly: https://duckdb.org/2024/05/03/vector-similarity-search-vss.h...

I have tinkered with using DuckDB as a poor man's vector database for a POC and had great results. One thing I'd love to see is being able to do some sort of row group level metadata statistics for embeddings within a parquet file - something that would allow various readers to push predicates down to an HTTP request metadata level and completely avoid loading in non-relevant rows to the database from a remote file -…

I thought about this some more and did some research - and found an indexing approach using HNSW, serialized to parquet, and queried from the browser here:

https://github.com/jasonjmcghee/portable-hnsw

Opens up efficient query patterns for larger datasets for RAG projects where you may not have the resources to run an expensive vector database

Re: The best way to use text embeddings portably is with Parquet and Polars

#43

The problem with Parquet is it’s static. Not good for use cases that involve continuous writes and updates. Although I have had good results with DuckDB and Parquet files in object storage. Fast load times. If you host your own embedding model, then you can transmit numpy float32 compressed arrays as bytes, then decode back into numpy arrays. Personally I prefer using SQLite with usearch extension. Binary vectors the…

> The problem with Parquet is it’s static. Not good for use cases that involve continuous writes and updates. Although I have had good results with DuckDB and Parquet files in object storage. Fast load times.

You can use glob patterns in DuckDB to query remote parquets though to get around this? Maybe break things up using a hive partitioning scheme or similar.

Re: The best way to use text embeddings portably is with Parquet and Polars

#44
post #40

I still don't like dataframes but oh my God Polars is so much better than pandas. I was doing some time series calculations, simple equity price adjustments basically, in Polars and my two thoughts were: - WTF, I can actually read the code and test it. - it's running so fast it seems like it's broken.

There’s some nice plugins too, some are finance related: https://github.com/ddotta/awesome-polars

The one thing I really want is for someone to make it so I can use it in F#. Presumably it's possible given how the python bit is implemented under the hood?

Re: The best way to use text embeddings portably is with Parquet and Polars

#45
post #42
post #25

Earlier quoted context omitted.

I have tinkered with using DuckDB as a poor man's vector database for a POC and had great results. One thing I'd love to see is being able to do some sort of row group level metadata statistics for embeddings within a parquet file - something that would allow various readers to push predicates down to an HTTP request metadata level and completely avoid loading in non-relevant rows to the database from a remote file -…

I thought about this some more and did some research - and found an indexing approach using HNSW, serialized to parquet, and queried from the browser here: https://github.com/jasonjmcghee/portable-hnsw Opens up efficient query patterns for larger datasets for RAG projects where you may not have the resources to run an expensive vector database

Hey that's my little research project- lmk if you're interested in chatting about this stuff.

As others have mentioned in other threads, parquet isn't a great tool for the job here, but you could theoretically build a different file format that lends itself better to the problem of static file(s) representing a vector database.

Re: The best way to use text embeddings portably is with Parquet and Polars

#46
post #44

Earlier quoted context omitted.

There’s some nice plugins too, some are finance related: https://github.com/ddotta/awesome-polars

The one thing I really want is for someone to make it so I can use it in F#. Presumably it's possible given how the python bit is implemented under the hood?

It uses pyo3 to generate the bindings, so you would have to find a similar crate for F#/.NET and port the polars Python FFI to it. If such a crate does not exist, it will be even more work.

Re: The best way to use text embeddings portably is with Parquet and Polars

#47

The problem with Parquet is it’s static. Not good for use cases that involve continuous writes and updates. Although I have had good results with DuckDB and Parquet files in object storage. Fast load times. If you host your own embedding model, then you can transmit numpy float32 compressed arrays as bytes, then decode back into numpy arrays. Personally I prefer using SQLite with usearch extension. Binary vectors the…

> The problem with Parquet is it’s static. Not good for use cases that involve continuous writes and updates.

parquet is columnar storage, so it’s use case is lots of heavy filtering/aggregation within analytical workloads (OLAP).

consistent writes / updates, i.e. basically transactional (OLTP), use cases are never going to have great performance in columnar storage. its the wrong format to use for that.

for faster writes/updates you’d want row-based, i.e. CSV or an actual database. which i’m glad to see is where you kind of ended up anyway.

Re: The best way to use text embeddings portably is with Parquet and Polars

#48
A neat trick in Vespa (vectors DB among other things) documentation is to use hex representation of vectors after converting them to binary.

This trick can be used to reduce your payload sizes. In Vespa, they support this format which is particularly useful when the same vectors are referenced multiple times in a document. For ColBERT or ColPaLi like cases (where you have many embedding vectors), this can reduce the size of the vectors stored on disk massively.

https://docs.vespa.ai/en/reference/document-json-format.html...

Not sure why this is not more commonly adopted though

Re: The best way to use text embeddings portably is with Parquet and Polars

#49
post #20

Earlier quoted context omitted.

That would get around memory limitations but I still think that would be slow.

You'd be surprised. As long as your query is using Polars natives and not a UDF (which drops it down to Python), you may get good results.

A (simple) benchmark would be great to figure out where the practical limits of such an approach are. Runtime is expected to grow with O(n*2) which will get painful at some point.

Re: The best way to use text embeddings portably is with Parquet and Polars

#50

The trouble with Parquet (and columnar storage) in ML is, 1. You don't really care too-much about accessing subsets of columns 2. You can't easily append stuff to closed Parquet files. 3. Batched-row access is presumably slower due to lower cache-hits. It's okay for map-reduce style stuff where this doesn't matter, but in ML these limitations are an annoyance. HDF5 (or Zarr, less portably) solves some/many of these i…

Re 2. Parquet can easily be used with chunked/partitioned files. Then appending is just adding another file/chunk.

The case of 1. really depends on the workload. For embeddings etc selecting column subsets is rare. In order cases, where one has a a bunch of separate features, doing column subsetting might be rather common. But yes, it is far from every case.

Post reply on HN