Comments (6)
Can you please explain the use case a bit more? What problem are you trying to solve? Why are you concatenating two vectors together?
from pgvector.
The vectors are color histograms for images. I'm using the histogram combinations as one element in a list of potential 'mood filters' for choosing an image.
I'd also like to try sampling imagenet vectors, since it turns out that averaging, say, VGG16's 7x7 blocks of 512, and then folding that down to sizes as small as 2 can preserve theme.
[256 is luminance(128) concatenated with greyscale(128)].
E.g. it just took 202 minutes to insert 6 permutations of NASNetLarge pre-averaged vectors on 100K records, albeit with 6 reads of all the vectors. Still, I'm sure 100K inserts would be noticeably faster than 600K.
from pgvector.
Hi @phobrain, you can use array slicing and expression indexing for this. For instance, to index and query the first 3 dimensions:
CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(5));
INSERT INTO items (embedding) VALUES ('[1,2,3,4,10000000]'), ('[5,6,7,8,9]');
CREATE INDEX ON items USING hnsw (((embedding::float4[])[0:3]::vector(3)) vector_l2_ops);
-- SET enable_seqscan = off; to use index when table has little data
SELECT * FROM items ORDER BY (embedding::float4[])[0:3]::vector(3) <-> '[1,2,3]'::vector LIMIT 5;
A function for slicing vectors could make this slightly simpler (vector_slice(embedding, 0, 3)
), but it doesn't seem like enough of an improvement or common enough to add right now.
from pgvector.
Thanks @ankane, that covers my immediate need, and I can implement vector_slice() as an sql generator.
Can one concatenate noncontiguous fields in that notation?
from pgvector.
Yes, Postgres also has an array_cat function:
CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3), embedding2 vector(2));
INSERT INTO items (embedding, embedding2) VALUES ('[1,2,3]', '[4,10000000]'), ('[5,6,7]', '[8,9]');
CREATE INDEX ON items USING hnsw ((array_cat(embedding::float4[], embedding2::float4[])::vector(5)) vector_l2_ops);
SELECT * FROM items ORDER BY array_cat(embedding::float4[], embedding2::float4[])::vector(5) <-> '[1,2,3,4,5]'::vector LIMIT 5;
from pgvector.
Just fyi, there will be a subvector
function and concat operator in 0.7.0 (#508).
SELECT subvector('[1,2,3,4,5]'::vector, 1, 3);
-- [1,2,3]
SELECT '[1,2,3]'::vector || '[4,5]';
-- [1,2,3,4,5]
from pgvector.
Related Issues (20)
- how to list existing databases in postgresql using python HOT 2
- HNSW Indexing and Filtering HOT 2
- A question about building index in background. HOT 1
- Installation instructions unclear HOT 1
- Large vector data type will cause performance decline? HOT 1
- A question regard table_open() in background worker when building index HOT 3
- jVector Implementation
- Type Error when working with Langchain (Missing Positional Argument: evalue) HOT 1
- pgvector still use row-based storage instead of columnar storage ? HOT 1
- Can't get the query planner to use HNSW index HOT 3
- 【search failed】 2000w、768dim, data search failed HOT 1
- ERROR: index row size 6160 exceeds btree version 4 maximum 2704 for index HOT 3
- Make difficulties HOT 2
- Table Insert Performance with HNSW Index HOT 3
- Comparison with high-precision data HOT 2
- Weight in the filters HOT 5
- can't make pgvector HOT 1
- src\bitvec.c(43): warning C4141: 'dllexport': used more than once HOT 6
- Porting indexes from pinecone to pgvector HOT 1
- Error when creating a halfvec_ip_ops index HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pgvector.