Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgresqlPackages.vectorchord: init at 0.2.2 #392710

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

diogotcorreia
Copy link
Member

Scalable, fast, and disk-friendly vector search in Postgres, the successor of pgvecto.rs.

https://github.com/tensorchord/VectorChord

Closes #392680

Probably going to be needed for Immich soon.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added the 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS label Mar 24, 2025
Comment on lines 14 to 25
CREATE EXTENSION vector;
CREATE EXTENSION vchord;

CREATE TABLE items (embedding vector(3));
INSERT INTO items (embedding) SELECT ARRAY[random(), random(), random()]::real[] FROM generate_series(1, 1000);

CREATE INDEX ON items USING vchordrq (embedding vector_l2_ops) WITH (options = $$
residual_quantization = true
[build.internal]
lists = [4096]
spherical_centroids = false
$$);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this kind of stuff as a passthru test via postgresqlTestExtension? I don't think we need a full nixos VM test for it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't know that existed, will look into that, thanks!

Copy link
Member Author

@diogotcorreia diogotcorreia Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done this, but the way I set finalPackage seems janky, do you have a better solution?
buildPgrxExtension does not currently support override-style functions, e.g.,

buildPgrxExtension (finalAttrs: {
  # ...
})

so I'm not sure what to do.

I don't mind trying to modify buildPgrxExtension to use lib.extendMkDerivation if that's desirable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind trying to modify buildPgrxExtension to use lib.extendMkDerivation if that's desirable.

Yes, I think it is.

Comment on lines 45 to 46
pgvector
vectorchord
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is pgvector a dependency here or is this a left-over?

If it's a hard dependency for vectorchord, maybe we can somehow propagate this automatically, when including vectorchord? (we might not have the infrastructure for it, yet, just thinking out loud here...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a dependency indeed. I didn't look that much into how to propagate it, but I agree that it should be done automatically (though not sure how).

Source (upstream readme): https://github.com/tensorchord/VectorChord?tab=readme-ov-file#requirements

Note that pgvector != pgvecto-rs

Copy link
Member Author

@diogotcorreia diogotcorreia Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a look at the postgres derivation and there does not seem to exist a way to achieve this at the moment. We would likely need to change the postgresqlWithPackages function to read some propagatedExtensions attribute from the derivations.

However, consider the following:

  • it would make it harder to override the versions of the dependencies (e.g., have pgvector from nixpkgs stable, but vectorchord from unstable), and could be confusing what propagates what;
  • the user already has to execute CREATE EXTENSION vector;, so they are aware of the dependency;
  • in this particular case, the main use case of this extension is Immich, which already has a NixOS module and will therefore handle this transparently anyway (as per the last point).

I'm not opposed to automatically propagate the dependency, but I don't see the need to. With that said, if you feel like it'd be better to propagate it, let me know and we'll figure something out infrastructure-wise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • the user already has to execute CREATE EXTENSION vector;, so they are aware of the dependency;

Note that you can do CREATE EXTENSION vchord CASCADE; if the extension's control file has declared the dependency properly.

it would make it harder to override the versions of the dependencies (e.g., have pgvector from nixpkgs stable, but vectorchord from unstable), and could be confusing what propagates what;

I think this could be dealt with if the "propagation" was a bit smart about it, for example it would only add the extension if it wasn't added manually already or so?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the extension's control file has declared the dependency properly.

Seems to be the case

for example it would only add the extension if it wasn't added manually already or so?

Could be an idea. Do you have the time to look into this or do you want me to do it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to, I still have a few other things on my plate right now!

Copy link
Contributor

@Titaniumtown Titaniumtown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff LGTM besides the comments made by others. I think we should hold off merging this until an immich release actually uses this. Thanks for the proactive PR @diogotcorreia !

@github-actions github-actions bot removed the 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS label Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Package request: VectorChord
4 participants