Submit a simple vector dimensionality reduction function. #582
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
I previously submitted a not-so-smart issue. Thank you everyone for your answers. I have come to understand the index limitations of PG, as well as some other useful knowledge. Particularly, pgvector: Fewer dimensions are better. Based on this article, I decided to tackle the dimensionality issue of ollama from a different angle.
During this period, I have written several dimensionality reduction algorithms. From the perspective of effectiveness and implementation complexity, the simplest method of partitioning and taking the average value is a good choice.
This function is not complicated; on the contrary, among the algorithms I have tried so far, this method is the simplest:
I have collected hundreds of sentences of text, including both Chinese and English, some technical articles and literary works, and compared the 4096-dimensional embedding vectors generated directly from ollama with the results of different compression methods. The norm algorithm compressed to 512 dimensions achieved the best results, and most of the time its search results are closer to the original 4096-dimensional vectors.
The Python script
test/python/generate_and_save.pyis used to generate test data, for example:Another Python script
test/python/ask.pyis used to compare search results, executed like this:python test/python/ask.py "They're playing our song."Perhaps, in addition to me, there may be users who need to generate compressed vectors of lower dimensions from high-dimensional embedding vectors. I hope this function can be of help.