Git Product home page Git Product logo

Comments (5)

olirice avatar olirice commented on May 28, 2024 1

Using the containment operator (@>) for equality should speed up metadata filtering

thanks!

use jsonb_path_ops for a smaller index size. "The non-default GIN operator class jsonb_path_ops does not support the key-exists operators, but it does support @>, @? and @@."

vecs doesn't support key exists filters so that sounds great

--

how does #12 look, does that address both the way you expected?

from vecs.

ankane avatar ankane commented on May 28, 2024 1

Just realized it probably shouldn't use containment if the query is a list/tuple or dict, since both the following are true but not equal:

SELECT '{"a": [1, 2, 3]}'::jsonb @> '{"a": [1]}';
SELECT '{"a": {"b": 1, "c": 2}}'::jsonb @> '{"a": {"b": 1}}';

Edit: It could use containment so the index is used, but should also recheck for equality.

from vecs.

ankane avatar ankane commented on May 28, 2024 1

Great! fwiw, it could be done in SQL with:

WHERE metadata @> '{"a": [1, 2]}' AND metadata -> 'a' = '[1, 2]'

from vecs.

ankane avatar ankane commented on May 28, 2024

Yeah, looks great!

from vecs.

olirice avatar olirice commented on May 28, 2024

makes sense, thanks

I added tests for the various edge cases to make sure its all working properly

The trouble with re-checking for equality in python after the results are returned is that it makes it difficult to get the exact number of results the user requested without potentially fetching more matches from the database. To avoid that, the containment optimization is limited to when the user provides a single value e.g. 6 or "abc".

from vecs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.