@nodetool-ai/vectorstore 0.7.0-rc.23 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -0
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/chroma-client.js.map +1 -1
- package/dist/collection-access.d.ts +51 -0
- package/dist/collection-access.d.ts.map +1 -0
- package/dist/collection-access.js +100 -0
- package/dist/collection-access.js.map +1 -0
- package/dist/embedding.d.ts +22 -9
- package/dist/embedding.d.ts.map +1 -1
- package/dist/embedding.js +33 -26
- package/dist/embedding.js.map +1 -1
- package/dist/index.d.ts +21 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +55 -45
- package/dist/index.js.map +1 -1
- package/dist/pinecone-provider.d.ts +30 -0
- package/dist/pinecone-provider.d.ts.map +1 -0
- package/dist/pinecone-provider.js +61 -0
- package/dist/pinecone-provider.js.map +1 -0
- package/dist/postgrest.d.ts +93 -0
- package/dist/postgrest.d.ts.map +1 -0
- package/dist/postgrest.js +250 -0
- package/dist/postgrest.js.map +1 -0
- package/dist/provider-factory.d.ts +23 -0
- package/dist/provider-factory.d.ts.map +1 -0
- package/dist/provider-factory.js +93 -0
- package/dist/provider-factory.js.map +1 -0
- package/dist/provider.d.ts +163 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +34 -0
- package/dist/provider.js.map +1 -0
- package/dist/sqlite-vec-provider.d.ts +38 -0
- package/dist/sqlite-vec-provider.d.ts.map +1 -0
- package/dist/sqlite-vec-provider.js +223 -0
- package/dist/sqlite-vec-provider.js.map +1 -0
- package/dist/sqlite-vec-store.d.ts +4 -2
- package/dist/sqlite-vec-store.d.ts.map +1 -1
- package/dist/sqlite-vec-store.js +28 -8
- package/dist/sqlite-vec-store.js.map +1 -1
- package/dist/supabase-provider.d.ts +60 -0
- package/dist/supabase-provider.d.ts.map +1 -0
- package/dist/supabase-provider.js +497 -0
- package/dist/supabase-provider.js.map +1 -0
- package/package.json +24 -8
- package/sql/supabase-migration.sql +104 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
-- NodeTool vector store — Supabase / pgvector migration
|
|
2
|
+
--
|
|
3
|
+
-- Run once against your Supabase project (SQL editor, supabase migration,
|
|
4
|
+
-- or psql). The provider (`@nodetool-ai/vectorstore` SupabaseProvider) talks
|
|
5
|
+
-- to PostgREST and the `nodetool_vec_match` RPC defined here — it does NOT
|
|
6
|
+
-- run DDL itself.
|
|
7
|
+
--
|
|
8
|
+
-- Layout: two shared tables — a registry and a records table — plus one
|
|
9
|
+
-- RPC for similarity search. PostgREST cannot use pgvector operators
|
|
10
|
+
-- directly (`<=>` / `<->` / `<#>`), so vector search is wrapped in a
|
|
11
|
+
-- function callable via `supabase.rpc('nodetool_vec_match', {...})`.
|
|
12
|
+
|
|
13
|
+
create extension if not exists vector;
|
|
14
|
+
|
|
15
|
+
-- Registry: one row per collection.
|
|
16
|
+
create table if not exists public.nodetool_vec_collections (
|
|
17
|
+
name text primary key,
|
|
18
|
+
metadata jsonb not null default '{}'::jsonb,
|
|
19
|
+
dimension int,
|
|
20
|
+
metric text not null default 'cosine'
|
|
21
|
+
check (metric in ('cosine', 'l2', 'ip')),
|
|
22
|
+
created_at timestamptz not null default now()
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
-- Records: shared table, partitioned logically by `collection`. Rows cascade
|
|
26
|
+
-- on rename/delete of the parent collection so the provider can rename
|
|
27
|
+
-- collections without rewriting every record.
|
|
28
|
+
create table if not exists public.nodetool_vec_records (
|
|
29
|
+
collection text not null
|
|
30
|
+
references public.nodetool_vec_collections(name)
|
|
31
|
+
on update cascade on delete cascade,
|
|
32
|
+
id text not null,
|
|
33
|
+
document text,
|
|
34
|
+
embedding vector,
|
|
35
|
+
uri text,
|
|
36
|
+
metadata jsonb not null default '{}'::jsonb,
|
|
37
|
+
primary key (collection, id)
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
create index if not exists nodetool_vec_records_collection_idx
|
|
41
|
+
on public.nodetool_vec_records (collection);
|
|
42
|
+
|
|
43
|
+
-- Optional: once your collection has a fixed dimension, create an ivfflat
|
|
44
|
+
-- index for fast approximate search. Cosine example for dimension 1536:
|
|
45
|
+
--
|
|
46
|
+
-- alter table public.nodetool_vec_records
|
|
47
|
+
-- alter column embedding type vector(1536) using embedding::vector(1536);
|
|
48
|
+
-- create index on public.nodetool_vec_records
|
|
49
|
+
-- using ivfflat (embedding vector_cosine_ops) with (lists = 100);
|
|
50
|
+
|
|
51
|
+
-- Similarity-search RPC. Distance operator is selected from the
|
|
52
|
+
-- collection's `metric` column. `p_metadata_filter` is applied as jsonb
|
|
53
|
+
-- containment (`@>`) — pass `{"k": "v"}` to require records whose
|
|
54
|
+
-- metadata contains that key/value. `p_document_match`, when non-null,
|
|
55
|
+
-- filters by case-insensitive substring match on the document column.
|
|
56
|
+
create or replace function public.nodetool_vec_match(
|
|
57
|
+
p_collection text,
|
|
58
|
+
p_query_embedding vector,
|
|
59
|
+
p_match_count int default 10,
|
|
60
|
+
p_metadata_filter jsonb default '{}'::jsonb,
|
|
61
|
+
p_document_match text default null
|
|
62
|
+
)
|
|
63
|
+
returns table (
|
|
64
|
+
id text,
|
|
65
|
+
document text,
|
|
66
|
+
uri text,
|
|
67
|
+
metadata jsonb,
|
|
68
|
+
distance float8
|
|
69
|
+
)
|
|
70
|
+
language plpgsql
|
|
71
|
+
stable
|
|
72
|
+
as $$
|
|
73
|
+
declare
|
|
74
|
+
metric_name text;
|
|
75
|
+
begin
|
|
76
|
+
select c.metric into metric_name
|
|
77
|
+
from public.nodetool_vec_collections c
|
|
78
|
+
where c.name = p_collection;
|
|
79
|
+
|
|
80
|
+
if metric_name is null then
|
|
81
|
+
raise exception 'Collection % not found', p_collection
|
|
82
|
+
using errcode = 'P0002';
|
|
83
|
+
end if;
|
|
84
|
+
|
|
85
|
+
return query
|
|
86
|
+
select r.id, r.document, r.uri, r.metadata,
|
|
87
|
+
case metric_name
|
|
88
|
+
when 'l2' then (r.embedding <-> p_query_embedding)::float8
|
|
89
|
+
when 'ip' then (r.embedding <#> p_query_embedding)::float8
|
|
90
|
+
else (r.embedding <=> p_query_embedding)::float8
|
|
91
|
+
end as distance
|
|
92
|
+
from public.nodetool_vec_records r
|
|
93
|
+
where r.collection = p_collection
|
|
94
|
+
and r.metadata @> p_metadata_filter
|
|
95
|
+
and (p_document_match is null
|
|
96
|
+
or r.document ilike '%' || p_document_match || '%')
|
|
97
|
+
order by case metric_name
|
|
98
|
+
when 'l2' then (r.embedding <-> p_query_embedding)
|
|
99
|
+
when 'ip' then (r.embedding <#> p_query_embedding)
|
|
100
|
+
else (r.embedding <=> p_query_embedding)
|
|
101
|
+
end
|
|
102
|
+
limit p_match_count;
|
|
103
|
+
end;
|
|
104
|
+
$$;
|