webcoderz commented on issue #1121:
URL: https://github.com/apache/age/issues/1121#issuecomment-3728015238
WIP as i mess with it more
# Apache AGE + pgvector
- **Apache AGE** (`age`) for Cypher queries
- **pgvector** (`vector`) for vector operations + ANN indexes
## Required session setup
AGE requires loading the extension and setting `search_path`:
```sql
LOAD 'age';
SET search_path = ag_catalog, public;
```
Why `public`?
- `vector` is installed into the `public` schema in our stack
- Cypher queries that cast to `::vector` (or call distance functions) need
`public` visible
- vector ops fail when `public` isn’t in the `search_path`, and start
working once it is.
## Basic Cypher execution from SQL
AGE is called through `cypher(graph_name, $$ ... $$)` and you must provide
an `AS (...)` return type list:
```sql
SELECT * FROM cypher('my_graph', $$ MATCH (n) RETURN n $$) AS (n agtype);
```
## Vector casts and operators inside Cypher
From the regression test, these casts are supported:
- `"[1.22,2.22,3.33]"::vector`
- `[1.22,2.22,3.33]::vector`
- `...::vector(3)` (dimension constrained)
And ordering by cosine distance works via the `<=>` operator:
```sql
SELECT * FROM cypher('graph', $$
MATCH (m:Movie)
RETURN m.title
ORDER BY m.embedding::vector(4) <=> [-0.1, 0.2, 0.3, -0.4]::vector(4)
ASC LIMIT 10
$$) AS (title agtype);
```
## Vector indexes (HNSW) on AGE vertex properties
The regression test demonstrates creating a HNSW index on a vertex property
by building an expression that extracts the property and casts it to
`vector(N)`:
1) Find the internal schema OID for the AGE graph
2) `CREATE INDEX ... USING hnsw ((... )::vector(N)) vector_cosine_ops;`
This is the core recipe to make vector similarity in AGE fast.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]