fix: register embedding functions in extension SQL and install v2.0.0 schema in Docker#136
Open
jjohare wants to merge 1 commit intoruvnet:mainfrom
Open
fix: register embedding functions in extension SQL and install v2.0.0 schema in Docker#136jjohare wants to merge 1 commit intoruvnet:mainfrom
jjohare wants to merge 1 commit intoruvnet:mainfrom
Conversation
… schema in Docker The Docker image builds ruvector.so with --features embeddings, compiling fastembed into the binary. However, the extension SQL files (ruvector--0.1.0.sql and ruvector--2.0.0.sql) contained only a comment stub for embedding functions instead of actual CREATE FUNCTION declarations. This meant CREATE EXTENSION ruvector never registered the embedding functions despite the compiled symbols being present in the .so. Additionally, the Dockerfile only copied ruvector--0.1.0.sql into the image while ruvector.control declares default_version = '2.0.0', causing CREATE EXTENSION ruvector to fail with "no installation script for version 2.0.0". Changes: - Replace embedding comment stubs in both ruvector--0.1.0.sql and ruvector--2.0.0.sql with actual CREATE FUNCTION declarations using the pgrx _wrapper symbol convention - Add ruvector_embed_vec() convenience function (text -> ruvector type) - Fix Dockerfile to copy both 0.1.0 and 2.0.0 SQL files into the image - Fix volatility markers in embeddings.sql (IMMUTABLE -> VOLATILE for functions that load models or mutate state) - Add embedding function smoke test to docker/init.sql Co-Authored-By: claude-flow <ruv@ruv.net>
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
Fix version mismatch: Dockerfile now copies both
ruvector--0.1.0.sqlandruvector--2.0.0.sqlinto the image. Previously only 0.1.0 was installed, butruvector.controldeclaresdefault_version = '2.0.0', causingCREATE EXTENSION ruvectorto fail with "no installation script for version 2.0.0".Register embedding functions: Both extension SQL files had a comment stub for embedding functions instead of actual
CREATE FUNCTIONdeclarations. The Docker build compiles fastembed intoruvector.sovia--features embeddings, and all_wrappersymbols are present in the binary, but PostgreSQL never knew about them. Replaced the stubs with 11 function declarations (10 C functions + 1 SQL convenience function).Fix volatility markers:
embeddings.sqlincorrectly marked stateful functions (ruvector_load_model,ruvector_embedding_models,ruvector_embed, etc.) asIMMUTABLE. Changed toVOLATILEwhere the function loads models, mutates cache state, or returns mutable results. Onlyruvector_embedding_dimsremainsIMMUTABLE(pure dimension lookup).Add
ruvector_embed_vec()convenience function:ruvector_embed()returnsreal[](PostgreSQL array format{...}), but theruvectortype expects bracket notation[...]. This SQL wrapper handles the conversion so users can doruvector_embed_vec('some text')::ruvector(384)in a single call.Add embedding smoke test to init.sql: Tests
ruvector_default_model()andruvector_embedding_dims()during container initialization.Root Cause
The extension SQL files (
ruvector--0.1.0.sql/ruvector--2.0.0.sql) were hand-crafted as a fallback becausecargo pgrx schemais unreliable in Docker. The embedding function declarations fromsql/embeddings.sqlwere never merged into these files — they only contained a note saying "build with --features embeddings", even though the Dockerfile does exactly that.Files Changed
crates/ruvector-postgres/Dockerfilecrates/ruvector-postgres/sql/ruvector--0.1.0.sqlcrates/ruvector-postgres/sql/ruvector--2.0.0.sqlcrates/ruvector-postgres/sql/embeddings.sqlruvector_embed_vec(), add _wrapper docscrates/ruvector-postgres/docker/init.sqlTest plan
docker build -f crates/ruvector-postgres/Dockerfile -t ruvector-postgres .CREATE EXTENSION ruvectorsucceeds (v2.0.0)SELECT ruvector_embed('hello world')returns 384-dim real[]SELECT ruvector_embed_vec('hello world')returns ruvector typeSELECT * FROM ruvector_embedding_models()lists 6 modelsSELECT ruvector_default_model()returnsall-MiniLM-L6-v2🤖 Generated with claude-flow