Vector Search Support - #571
Open
yabsp wants to merge 73 commits into
Open
Conversation
…a retrieval and basic distance function pushdown of vectors.
…n for PostgreSQL sources
…d distance functions - enabling pushdown possibility
This reverts commit 275a50f.
…available docker images
… type info gathering
…lypheny available docker images" This reverts commit e3de020.
…nd refactor dialect pushdown API around ElementType
…available docker images
…parsing for aliased SQL types
… discovery coverage
… and add tests for PIPreparedIndexedStatement and PIPreparedNamedStatement
This reverts commit 14aab81.
Contributor
|
Related UI PR: polypheny/Polypheny-UI#111 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR integrates vector similarity search into Polypheny by extending the PostgreSQL adapter with support for the pgvector extension.
Vectors become a typed value rather than an opaque array, adapters advertise their vector capabilities through a new feature-detection mechanism, and the planner pushes distance computation down to a capable store. Where a store cannot evaluate a distance natively, Polypheny falls back to its internal distance functions, so functionality never depends on a particular adapter.
Six metrics — L1, L2, cosine, inner product (float vectors) and Hamming, Jaccard (bit vectors) — are exposed from SQL, MQL, and Cypher. HNSW and IVFFlat indexes can be created from SQL DDL and from the web interface.
Changes
elementsNullablefor array and collection types, parsed from<type> NOT NULL ARRAY(1, n)and cascaded throughLogicalColumn,PhysicalColumn,RelationalCatalog, andDdlManager. Because it is a serialized field onLogicalColumn, a catalog persisted by an earlier build cannot be deserialized and is rebuilt from the data.SqlDbFeatureinterface with a per-adapter enum (PostgresqlFeature:PGVECTOR,POSTGIS);SqlDialectanswers throughsupportsFeature()/supportsVector(). Features are known for Docker-managed stores viaPostgresqlImageVariantand detected by queryingpg_extensionfor remote stores and sources.CheckingKnnFunctionSupportVisitor,CheckingKnnFunctionVisitor) guard theJdbcRulespredicates, so a distance is delegated only when the target dialect can evaluate it.L1_DISTANCE,L2_DISTANCE,COS_DISTANCE,INNER_PRODUCT_DISTANCE,HAMMING_DISTANCE,JACCARD_DISTANCE) encode the metric in their ownKind, lettingPostgresqlSqlDialect.unparseCallemit native pgvector operators.JdbcJoinRulenow pushes down aTRUE-condition join when both inputs carry a vector column and the dialect supports vectors. Every other Cartesian product keeps the old behavior.ALTER TABLE ... ADD INDEXgains aWITH (key=value)clause. Indexes are grouped by a newIndexCategory(VECTOR), andIndexMethodModelcarries a category plusIndexParameterModels that the web interface renders its dialog from.AbstractJdbcSourcegains afetchColumnMetadatahook; for PostgreSQL it readsattndimsandatttypmodto recover array and pgvector dimensions.SqlDialect.initializeConnectionhook (PGvector,PGbit,PGgeometry).ResultSetEnumerable.setDynamicParambindsVectorTypeparameters as native objects, andJdbcToEnumerableConverterreads them back viagetCustomArrayRetrievalExpression.pgvector0.1.6; bumpedbouncycastle1.80 → 1.80.2 and replaced the four hardcodedallowDependencyversions with thebouncycastle_versionproperty.Features
VectorTypefor fixed-dimension float and bit vectors, carried through parsing, validation, planning, and prepared statements.<+>,<->,<=>,<#>,<~>,<%>), four supported by the generic, pre-existingDISTANCEfunction.$vectorSearchstage withpath,queryVector,metric,limit, and an optionalfilter.vector_distance(property, queryVector, metric).m,ef_construction,lists) and metric selection.Bug Fixes
Tests
SqlPgvectorOperatorTest— all six metrics through both invocation forms, including filtered and cross-join shapes.ArrayNotNullConstraintTest— element-levelNOT NULLenforcement for literal arrays and parameterized query vectors.JdbcBooleanArrayTest— bit vector insertion, binding, and retrieval round trip.MqlVectorDistanceTest/CypherVectorDistanceTest—$vectorSearchandvector_distancesyntax, lowering, and validation.PostgresqlSqlDialectTest/PostgresqlVectorHelperTest— unparsing, cast handling, and dynamic-parameter emission.PostgresqlSourceTest/PostgresqlSourceDiscoveryTest— feature detection and dimension discovery on a source.PreparedIndexedStatementTest/PreparedNamedStatementTest—ARRAY/VectorTypepreserved through the Prism interface.ComplexViewTest,CatalogTransactionTest,SqlParserTest, and the Neo4j tests.ToDo
DISTANCEfunction additionally toHAMMING_DISTANCEandJACCARD_DISTANCE(as for now the non-parameterized versions must be used)