Skip to content

Commit 3a4d52a

Browse files
authored
Merge pull request #760 from constructive-io/devin/1772321033-graphile-pgvector-plugin
feat: add graphile-pgvector-plugin, switch graphile-settings to use it
2 parents d7c89cc + 31b13c5 commit 3a4d52a

16 files changed

Lines changed: 3731 additions & 7723 deletions

File tree

.github/workflows/run-tests.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ jobs:
7575
env: {}
7676
- package: graphile/graphile-authz
7777
env: {}
78+
- package: graphile/graphile-pgvector-plugin
79+
env: {}
7880
- package: graphile/postgraphile-plugin-pgvector
7981
env: {}
8082
- package: graphql/server-test
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# graphile-pgvector-plugin
2+
3+
PostGraphile v5 codec plugin for [pgvector](https://github.com/pgvector/pgvector) — makes `vector` columns, mutations, and SQL functions work automatically.
4+
5+
## How it works
6+
7+
This plugin registers a **codec** for the pgvector `vector` type. Without it, PostGraphile silently ignores `vector(n)` columns and skips SQL functions that accept `vector` arguments.
8+
9+
Once installed:
10+
11+
- `vector(n)` columns appear on GraphQL output types
12+
- `vector(n)` columns appear in `create` / `update` mutation inputs
13+
- SQL functions with `vector` arguments are exposed as query/mutation fields
14+
- A `Vector` GraphQL scalar handles serialization (`[Float]`)
15+
16+
## Installation
17+
18+
```bash
19+
pnpm add graphile-pgvector-plugin
20+
```
21+
22+
## Prerequisites
23+
24+
- PostgreSQL with pgvector extension installed
25+
- PostGraphile v5
26+
27+
## Usage
28+
29+
```typescript
30+
import { VectorCodecPreset } from 'graphile-pgvector-plugin';
31+
32+
const preset = {
33+
extends: [
34+
// ...other presets
35+
VectorCodecPreset,
36+
],
37+
};
38+
```
39+
40+
Zero configuration required. Any table with a `vector` column just works.
41+
42+
## GraphQL Examples
43+
44+
```graphql
45+
# Vector columns appear on types automatically
46+
query {
47+
contacts {
48+
nodes {
49+
id
50+
name
51+
embedding
52+
}
53+
}
54+
}
55+
56+
# SQL functions with vector args are auto-exposed
57+
query {
58+
searchContacts(queryEmbedding: [0.1, 0.2, 0.3]) {
59+
nodes {
60+
id
61+
name
62+
}
63+
}
64+
}
65+
66+
# Mutations include vector columns
67+
mutation {
68+
createContact(input: { name: "Test", embedding: [0.1, 0.2, 0.3] }) {
69+
contact {
70+
id
71+
embedding
72+
}
73+
}
74+
}
75+
```
76+
77+
## License
78+
79+
MIT
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
transform: {
6+
'^.+\\.tsx?$': [
7+
'ts-jest',
8+
{
9+
babelConfig: false,
10+
tsconfig: 'tsconfig.json'
11+
}
12+
]
13+
},
14+
transformIgnorePatterns: [`/node_modules/*`],
15+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
16+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
17+
modulePathIgnorePatterns: ['dist/*']
18+
};
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"name": "graphile-pgvector-plugin",
3+
"version": "1.0.0",
4+
"description": "PostGraphile v5 codec plugin for pgvector — makes vector columns, mutations, and functions work automatically",
5+
"author": "Constructive <developers@constructive.io>",
6+
"homepage": "https://github.com/constructive-io/constructive",
7+
"license": "MIT",
8+
"main": "index.js",
9+
"module": "esm/index.js",
10+
"types": "index.d.ts",
11+
"scripts": {
12+
"clean": "makage clean",
13+
"prepack": "npm run build",
14+
"build": "makage build",
15+
"build:dev": "makage build --dev",
16+
"lint": "eslint . --fix",
17+
"test": "jest",
18+
"test:watch": "jest --watch"
19+
},
20+
"publishConfig": {
21+
"access": "public",
22+
"directory": "dist"
23+
},
24+
"repository": {
25+
"type": "git",
26+
"url": "https://github.com/constructive-io/constructive"
27+
},
28+
"bugs": {
29+
"url": "https://github.com/constructive-io/constructive/issues"
30+
},
31+
"devDependencies": {
32+
"@types/node": "^22.19.1",
33+
"@types/pg": "^8.16.0",
34+
"graphile-test": "workspace:^",
35+
"makage": "^0.1.10",
36+
"pg": "^8.17.1",
37+
"pgsql-test": "workspace:^"
38+
},
39+
"peerDependencies": {
40+
"graphile-build": "5.0.0-rc.4",
41+
"graphile-build-pg": "5.0.0-rc.5",
42+
"graphile-config": "1.0.0-rc.5",
43+
"graphql": "^16.9.0",
44+
"pg-sql2": "5.0.0-rc.4",
45+
"postgraphile": "5.0.0-rc.7"
46+
},
47+
"keywords": [
48+
"postgraphile",
49+
"graphile",
50+
"constructive",
51+
"plugin",
52+
"postgres",
53+
"graphql",
54+
"pgvector",
55+
"vector",
56+
"embeddings",
57+
"ai"
58+
]
59+
}

0 commit comments

Comments
 (0)