Skip to content

Commit

Permalink
fix(postgres): Handle vector extension creation properly (elizaOS#1561)
Browse files Browse the repository at this point in the history
- Add proper checks for vector extension existence

- Create extensions schema if not exists

- Add extensions schema to search path

- Ensure idempotent schema creation
  • Loading branch information
AIFlowML committed Jan 3, 2025
1 parent 76d4f42 commit c988a2f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/adapter-postgres/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,26 @@
-- DROP TABLE IF EXISTS rooms CASCADE;
-- DROP TABLE IF EXISTS accounts CASCADE;

-- Create extensions schema first
CREATE SCHEMA IF NOT EXISTS extensions;

DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_extension
WHERE extname = 'vector'
) THEN
CREATE EXTENSION vector
SCHEMA extensions;
END IF;
END $$;

CREATE EXTENSION IF NOT EXISTS vector;
CREATE EXTENSION IF NOT EXISTS fuzzystrmatch;

-- Add extensions schema to search path
SET search_path TO public, extensions;

-- Create a function to determine vector dimension
CREATE OR REPLACE FUNCTION get_embedding_dimension()
RETURNS INTEGER AS $$
Expand Down

0 comments on commit c988a2f

Please sign in to comment.