Skip to content

[pgvector] Target netstandard2.0 again - #48

Closed
roji wants to merge 1 commit into
pgvector:masterfrom
roji:TargetNetstandard20
Closed

roji wants to merge 1 commit into
pgvector:masterfrom
roji:TargetNetstandard20

Conversation

@roji

@roji roji commented Mar 20, 2025

Copy link
Copy Markdown
Contributor

Hey @ankane 👋

I'm currently working intensively on a .NET abstraction for vector databases - Microsoft.Extensions.VectorData; see this announcement (though we've made considerable progress since). PgVector is obviously an important implementation and we're working to make it work nicely there.

One thing we've centralized on is netstandard2.0 and net462 support across the board - wherever possible - to make sure absolutely everyone can do vector search: there are quite a few applications out there still stuck on .NET Framework, and I'm trying to make sure nobody gets left out. I noticed that pgvector 0.3.0 dropped netstandard2.0 support, presumably because of the added support for the .NET Half type, which was only introduced in .NET 5.0.

So here's a PR adding back netstandard2.0, using simple conditional compilation to not have Half there; it's all pretty straightforward and allows .NET Framework users to use float embeddings. Note that it also adds a net462 target explicitly - that's recommended since netstandard2.0 has issues under .NET Framework 4.7.2 (docs, under "CONSIDER adding a target for net462 when you're offering a netstandard2.0 target"). None of that complicates the code in any significant way.

Additional things I threw in:

  • Bump dependency patch versions
  • Simplify to just one Npgsql PgTypeInfoResolverFactory to registers all three vector types, instead of three separate ones (that's what we usually do with plugins).

@roji roji changed the title Target netstandard2.0 again [pgvector] Target netstandard2.0 again Mar 20, 2025
ankane added a commit that referenced this pull request Mar 20, 2025
@ankane

ankane commented Mar 20, 2025

Copy link
Copy Markdown
Member

Hi @roji, thanks for the PR! Merged the FactoryResolver change in the commit above.

I think support for netstandard2.0 should be fine if we can ensure both paths are tested on CI.

@roji

roji commented Mar 20, 2025

Copy link
Copy Markdown
Contributor Author

@ankane that would require setting up a build with .NET Framework, on a Windows machine (or Linux with mono - let me know if you have a preference). The sort of stuff being done in the plugin is generally very portable and differences between .NET Framework and Core are very unlikely to affect it; but if you think that CI test coverage is important here (as opposed to a one-time test which I can certainly do), let me know and I'll do it.

@ankane

ankane commented Mar 20, 2025

Copy link
Copy Markdown
Member

Looks like it'll fail to compile if any of the guards are missing, so think that should be fine. Need to get some sleep, but will look at this tomorrow.

@roji

roji commented Mar 20, 2025 •

Copy link
Copy Markdown
Contributor Author

Sounds good, thanks! Will rebase on top of latest master.

Plus:
* Bump dependency patch versions
* Minor simplification
@roji
roji force-pushed the TargetNetstandard20 branch from 7962d0a to 8f85c6f Compare March 20, 2025 10:53
@ankane

ankane commented Mar 20, 2025

Copy link
Copy Markdown
Member

I just noticed Npgsql no longer supports netstandard2.0 (as of 9.0), so the next minor release of the Pgvector package (0.4.0) will probably do the same.

I'm not sure if there's much benefit to adding this and releasing it as 0.3.1 since:

  • the vector type works with 0.2.0
  • the halfvec type will be excluded from netstandard2.0
  • the bit type doesn't need any package (uses BitArray)
  • the sparsevec type would be the only difference, but it's probably the least popular type

Thoughts?

@roji

roji commented Mar 21, 2025

Copy link
Copy Markdown
Contributor Author

@ankane I'd advise to not necessarily eagerly bump the Npgsql dependency unless there's a good reason to - the extensions should work fine on both Npgsql 8.0 and 9.0 (am happy to submit a PR that adds CI testing for that), and as pgvector evolves, it's better not to lose users for no good reason. With Npgsql 8.0 specifically it's even stronger, precisely because it's the last version to support .NET Framework/.NET Standard. We know that there are quite a lot of framework users out there, which ideally would be able to use the latest pgvector versions - unless that places an unreasonable burden on this library. Let me know what you think.

So yeah, this is currently about allowing sparsevec to Framework users, but also any types/functionality you add tomorrow.

@ankane ankane closed this in 3eb8548 Mar 21, 2025
@ankane

ankane commented Mar 21, 2025

Copy link
Copy Markdown
Member

Thanks, will support it for now (although I don't think the situation is too different from npgsql/npgsql#5296).

It'd be nice to test both Npgsql 8 and 9 on CI (as well as .NET 9) if it doesn't add too much complexity.

@roji

roji commented Mar 21, 2025 •

Copy link
Copy Markdown
Contributor Author

Thanks, will support it for now (although I don't think the situation is too different from npgsql/npgsql#5296).

You're right in a way - it's mostly that Npgsql is a much bigger beast and keeping netstandard2.0 was much more of a maintenance and performance drag, whereas here it seems to be mostly free (except for those few #if directives).

In any case thanks - I'll put together a PR for adding tesing.

@ankane

ankane commented Mar 21, 2025

Copy link
Copy Markdown
Member

Sounds good. Will release 0.3.1 for both packages tonight.

Also, I tried tackling #44 a bit ago but didn't have any luck if you have the spare cycles.

@roji

roji commented Mar 21, 2025

Copy link
Copy Markdown
Contributor Author

Will take a look - in principle, if the types are probably registered with EF's TypeMappingSource, everything should just work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants