Skip to content

[eng 1944] Ensure/test pgvector compatibility#22

Merged
conniedonahue merged 10 commits intomainfrom
connor/eng-1944-ensuretest-that-our-functionality-works-with
Jul 17, 2025
Merged

[eng 1944] Ensure/test pgvector compatibility#22
conniedonahue merged 10 commits intomainfrom
connor/eng-1944-ensuretest-that-our-functionality-works-with

Conversation

@conniedonahue
Copy link
Copy Markdown
Contributor

@conniedonahue conniedonahue commented Jul 8, 2025

Changes:

  • Adds the pgvector plugin to the library and tests a few functions using vector search
    • note: I allow for earlier versions of numpy if the user is on python <3.10.
  • Adds an optional embeddings field to the Document model
  • Updates the test setup so that we pull from a pgvector-compatible postgres image

Some things for separate tickets:

  • see if we can add stubs for proper Vector typing
    • I gave it a go before deciding to break it off for later -- it was a bit daunting!
    • currently, all of the embeddings functions (e.g. l2_distance) are greyed out // return "Any"
  • add overloads to select like we did with query (just noting this hasn't been done yet)

@conniedonahue conniedonahue requested a review from Copilot July 8, 2025 19:36
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds pgvector support to the library and updates tests to verify vector-based search works under Oso authorization.

  • Introduces an optional embedding field on Document backed by pgvector
  • Updates test setup to use a pgvector-enabled Postgres image and create the extension
  • Adds numerous tests exercising L2, cosine, and inner-product searches via both ORM and Core APIs
Comments suppressed due to low confidence (1)

Comment thread tests/test_pgvector.py Outdated
Comment thread tests/conftest.py
@conniedonahue conniedonahue marked this pull request as ready for review July 8, 2025 19:41
@conniedonahue conniedonahue requested a review from vrama628 July 8, 2025 19:41
Copy link
Copy Markdown
Contributor

@vrama628 vrama628 left a comment

Choose a reason for hiding this comment

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

nice! Left a few non-blocking comments about whether certain things are necessary

Comment thread pyproject.toml Outdated
pgvector = "^0.4.1"
numpy = [
{ version = ">=1.21.0,<2.0", python = "<3.10" },
{ version = ">=2.1.0", python = ">=3.10" },
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what's the purpose of specifying 2.1.0 for >=3.10?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is to ensure compatibility with our lowest accepted python version (3.9) and the latest python version (3.13.5). I ran python on both of these versions while testing. Essentially:

  • pgvector requires numpy
  • Numpy drops support for 3.9 at 2.1.0
  • the highest version of numpy that supports 3.9, 2.0.1 supports up to 3.12, so not 3.13+ :(
  • any Python users at 3.13+ would have to use a more recent numpy version.

I thought we might as well use 2.1+ for 3.10, and I carved out this earlier version of numpy for applications python 3.9.

I'll test manually, but I'll see if i can up the version of the python 3.9 version of numpy to 2.0.1:

numpy = [
    { version = ">=1.21.0,<2.1.0", python = "<3.10" },
    { version = ">=2.1.0", python = ">=3.10" },
]

Comment thread tests/conftest.py Outdated
Comment thread tests/models.py Outdated
Comment thread tests/test_pgvector.py
@conniedonahue conniedonahue merged commit a400d11 into main Jul 17, 2025
4 checks passed
@conniedonahue conniedonahue deleted the connor/eng-1944-ensuretest-that-our-functionality-works-with branch July 17, 2025 19:55
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants