@vectorstores/supabase 0.1.4 → 0.1.6
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/dist/index.cjs +46 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.edge-light.d.ts +2 -0
- package/dist/index.edge-light.js +47 -1
- package/dist/index.js +47 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -71,6 +71,26 @@ class SupabaseVectorStore extends core.BaseVectorStore {
|
|
|
71
71
|
* @returns Object containing matched nodes, similarity scores, and document IDs
|
|
72
72
|
* @throws Error if query embedding is not provided or if the query fails
|
|
73
73
|
*/ async query(query, options) {
|
|
74
|
+
switch(query.mode){
|
|
75
|
+
case "bm25":
|
|
76
|
+
return this.bm25Search(query);
|
|
77
|
+
case "hybrid":
|
|
78
|
+
{
|
|
79
|
+
// Calculate prefetch limit for sub-searches
|
|
80
|
+
const prefetchK = query.hybridPrefetch ?? query.similarityTopK * core.DEFAULT_HYBRID_PREFETCH_MULTIPLIER;
|
|
81
|
+
const prefetchQuery = {
|
|
82
|
+
...query,
|
|
83
|
+
similarityTopK: prefetchK
|
|
84
|
+
};
|
|
85
|
+
const vectorResult = await this.vectorSearch(prefetchQuery);
|
|
86
|
+
const bm25Result = await this.bm25Search(prefetchQuery);
|
|
87
|
+
return core.combineResults(vectorResult, bm25Result, query.alpha ?? 0.5, query.similarityTopK);
|
|
88
|
+
}
|
|
89
|
+
default:
|
|
90
|
+
return this.vectorSearch(query);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
async vectorSearch(query) {
|
|
74
94
|
if (!query.queryEmbedding) {
|
|
75
95
|
throw new Error("Query embedding is required");
|
|
76
96
|
}
|
|
@@ -104,6 +124,32 @@ class SupabaseVectorStore extends core.BaseVectorStore {
|
|
|
104
124
|
ids: searchedEmbeddingResponses.map((item)=>item.id)
|
|
105
125
|
};
|
|
106
126
|
}
|
|
127
|
+
async bm25Search(query) {
|
|
128
|
+
if (!query.queryStr) {
|
|
129
|
+
throw new Error("Query string is required for BM25 search");
|
|
130
|
+
}
|
|
131
|
+
const { data, error } = await this.supabaseClient.from(this.table).select("*").textSearch("content", query.queryStr).limit(query.similarityTopK);
|
|
132
|
+
if (error) {
|
|
133
|
+
throw new Error(`Error querying vector store: ${JSON.stringify(error, null, 2)}`);
|
|
134
|
+
}
|
|
135
|
+
const nodes = (data || []).map((item)=>{
|
|
136
|
+
const node = core.metadataDictToNode(item.metadata ?? {}, {
|
|
137
|
+
fallback: {
|
|
138
|
+
id: item.id,
|
|
139
|
+
text: item.content,
|
|
140
|
+
metadata: item.metadata
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
node.embedding = item.embedding;
|
|
144
|
+
node.setContent(item.content);
|
|
145
|
+
return node;
|
|
146
|
+
});
|
|
147
|
+
return {
|
|
148
|
+
nodes,
|
|
149
|
+
similarities: nodes.map(()=>1.0),
|
|
150
|
+
ids: (data || []).map((item)=>item.id)
|
|
151
|
+
};
|
|
152
|
+
}
|
|
107
153
|
/**
|
|
108
154
|
* Converts metadata filters to supabase query filter format
|
|
109
155
|
* @param queryFilters - Metadata filters to convert
|
package/dist/index.d.cts
CHANGED
|
@@ -46,6 +46,8 @@ declare class SupabaseVectorStore extends BaseVectorStore {
|
|
|
46
46
|
* @throws Error if query embedding is not provided or if the query fails
|
|
47
47
|
*/
|
|
48
48
|
query(query: VectorStoreQuery, options?: object): Promise<VectorStoreQueryResult>;
|
|
49
|
+
private vectorSearch;
|
|
50
|
+
private bm25Search;
|
|
49
51
|
/**
|
|
50
52
|
* Converts metadata filters to supabase query filter format
|
|
51
53
|
* @param queryFilters - Metadata filters to convert
|
package/dist/index.d.ts
CHANGED
|
@@ -46,6 +46,8 @@ declare class SupabaseVectorStore extends BaseVectorStore {
|
|
|
46
46
|
* @throws Error if query embedding is not provided or if the query fails
|
|
47
47
|
*/
|
|
48
48
|
query(query: VectorStoreQuery, options?: object): Promise<VectorStoreQueryResult>;
|
|
49
|
+
private vectorSearch;
|
|
50
|
+
private bm25Search;
|
|
49
51
|
/**
|
|
50
52
|
* Converts metadata filters to supabase query filter format
|
|
51
53
|
* @param queryFilters - Metadata filters to convert
|
|
@@ -46,6 +46,8 @@ declare class SupabaseVectorStore extends BaseVectorStore {
|
|
|
46
46
|
* @throws Error if query embedding is not provided or if the query fails
|
|
47
47
|
*/
|
|
48
48
|
query(query: VectorStoreQuery, options?: object): Promise<VectorStoreQueryResult>;
|
|
49
|
+
private vectorSearch;
|
|
50
|
+
private bm25Search;
|
|
49
51
|
/**
|
|
50
52
|
* Converts metadata filters to supabase query filter format
|
|
51
53
|
* @param queryFilters - Metadata filters to convert
|
package/dist/index.edge-light.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createClient } from '@supabase/supabase-js';
|
|
2
|
-
import { BaseVectorStore, nodeToMetadata, MetadataMode, metadataDictToNode } from '@vectorstores/core';
|
|
2
|
+
import { BaseVectorStore, nodeToMetadata, MetadataMode, DEFAULT_HYBRID_PREFETCH_MULTIPLIER, combineResults, metadataDictToNode } from '@vectorstores/core';
|
|
3
3
|
import { getEnv } from '@vectorstores/env';
|
|
4
4
|
|
|
5
5
|
class SupabaseVectorStore extends BaseVectorStore {
|
|
@@ -69,6 +69,26 @@ class SupabaseVectorStore extends BaseVectorStore {
|
|
|
69
69
|
* @returns Object containing matched nodes, similarity scores, and document IDs
|
|
70
70
|
* @throws Error if query embedding is not provided or if the query fails
|
|
71
71
|
*/ async query(query, options) {
|
|
72
|
+
switch(query.mode){
|
|
73
|
+
case "bm25":
|
|
74
|
+
return this.bm25Search(query);
|
|
75
|
+
case "hybrid":
|
|
76
|
+
{
|
|
77
|
+
// Calculate prefetch limit for sub-searches
|
|
78
|
+
const prefetchK = query.hybridPrefetch ?? query.similarityTopK * DEFAULT_HYBRID_PREFETCH_MULTIPLIER;
|
|
79
|
+
const prefetchQuery = {
|
|
80
|
+
...query,
|
|
81
|
+
similarityTopK: prefetchK
|
|
82
|
+
};
|
|
83
|
+
const vectorResult = await this.vectorSearch(prefetchQuery);
|
|
84
|
+
const bm25Result = await this.bm25Search(prefetchQuery);
|
|
85
|
+
return combineResults(vectorResult, bm25Result, query.alpha ?? 0.5, query.similarityTopK);
|
|
86
|
+
}
|
|
87
|
+
default:
|
|
88
|
+
return this.vectorSearch(query);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async vectorSearch(query) {
|
|
72
92
|
if (!query.queryEmbedding) {
|
|
73
93
|
throw new Error("Query embedding is required");
|
|
74
94
|
}
|
|
@@ -102,6 +122,32 @@ class SupabaseVectorStore extends BaseVectorStore {
|
|
|
102
122
|
ids: searchedEmbeddingResponses.map((item)=>item.id)
|
|
103
123
|
};
|
|
104
124
|
}
|
|
125
|
+
async bm25Search(query) {
|
|
126
|
+
if (!query.queryStr) {
|
|
127
|
+
throw new Error("Query string is required for BM25 search");
|
|
128
|
+
}
|
|
129
|
+
const { data, error } = await this.supabaseClient.from(this.table).select("*").textSearch("content", query.queryStr).limit(query.similarityTopK);
|
|
130
|
+
if (error) {
|
|
131
|
+
throw new Error(`Error querying vector store: ${JSON.stringify(error, null, 2)}`);
|
|
132
|
+
}
|
|
133
|
+
const nodes = (data || []).map((item)=>{
|
|
134
|
+
const node = metadataDictToNode(item.metadata ?? {}, {
|
|
135
|
+
fallback: {
|
|
136
|
+
id: item.id,
|
|
137
|
+
text: item.content,
|
|
138
|
+
metadata: item.metadata
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
node.embedding = item.embedding;
|
|
142
|
+
node.setContent(item.content);
|
|
143
|
+
return node;
|
|
144
|
+
});
|
|
145
|
+
return {
|
|
146
|
+
nodes,
|
|
147
|
+
similarities: nodes.map(()=>1.0),
|
|
148
|
+
ids: (data || []).map((item)=>item.id)
|
|
149
|
+
};
|
|
150
|
+
}
|
|
105
151
|
/**
|
|
106
152
|
* Converts metadata filters to supabase query filter format
|
|
107
153
|
* @param queryFilters - Metadata filters to convert
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createClient } from '@supabase/supabase-js';
|
|
2
|
-
import { BaseVectorStore, nodeToMetadata, MetadataMode, metadataDictToNode } from '@vectorstores/core';
|
|
2
|
+
import { BaseVectorStore, nodeToMetadata, MetadataMode, DEFAULT_HYBRID_PREFETCH_MULTIPLIER, combineResults, metadataDictToNode } from '@vectorstores/core';
|
|
3
3
|
import { getEnv } from '@vectorstores/env';
|
|
4
4
|
|
|
5
5
|
class SupabaseVectorStore extends BaseVectorStore {
|
|
@@ -69,6 +69,26 @@ class SupabaseVectorStore extends BaseVectorStore {
|
|
|
69
69
|
* @returns Object containing matched nodes, similarity scores, and document IDs
|
|
70
70
|
* @throws Error if query embedding is not provided or if the query fails
|
|
71
71
|
*/ async query(query, options) {
|
|
72
|
+
switch(query.mode){
|
|
73
|
+
case "bm25":
|
|
74
|
+
return this.bm25Search(query);
|
|
75
|
+
case "hybrid":
|
|
76
|
+
{
|
|
77
|
+
// Calculate prefetch limit for sub-searches
|
|
78
|
+
const prefetchK = query.hybridPrefetch ?? query.similarityTopK * DEFAULT_HYBRID_PREFETCH_MULTIPLIER;
|
|
79
|
+
const prefetchQuery = {
|
|
80
|
+
...query,
|
|
81
|
+
similarityTopK: prefetchK
|
|
82
|
+
};
|
|
83
|
+
const vectorResult = await this.vectorSearch(prefetchQuery);
|
|
84
|
+
const bm25Result = await this.bm25Search(prefetchQuery);
|
|
85
|
+
return combineResults(vectorResult, bm25Result, query.alpha ?? 0.5, query.similarityTopK);
|
|
86
|
+
}
|
|
87
|
+
default:
|
|
88
|
+
return this.vectorSearch(query);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async vectorSearch(query) {
|
|
72
92
|
if (!query.queryEmbedding) {
|
|
73
93
|
throw new Error("Query embedding is required");
|
|
74
94
|
}
|
|
@@ -102,6 +122,32 @@ class SupabaseVectorStore extends BaseVectorStore {
|
|
|
102
122
|
ids: searchedEmbeddingResponses.map((item)=>item.id)
|
|
103
123
|
};
|
|
104
124
|
}
|
|
125
|
+
async bm25Search(query) {
|
|
126
|
+
if (!query.queryStr) {
|
|
127
|
+
throw new Error("Query string is required for BM25 search");
|
|
128
|
+
}
|
|
129
|
+
const { data, error } = await this.supabaseClient.from(this.table).select("*").textSearch("content", query.queryStr).limit(query.similarityTopK);
|
|
130
|
+
if (error) {
|
|
131
|
+
throw new Error(`Error querying vector store: ${JSON.stringify(error, null, 2)}`);
|
|
132
|
+
}
|
|
133
|
+
const nodes = (data || []).map((item)=>{
|
|
134
|
+
const node = metadataDictToNode(item.metadata ?? {}, {
|
|
135
|
+
fallback: {
|
|
136
|
+
id: item.id,
|
|
137
|
+
text: item.content,
|
|
138
|
+
metadata: item.metadata
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
node.embedding = item.embedding;
|
|
142
|
+
node.setContent(item.content);
|
|
143
|
+
return node;
|
|
144
|
+
});
|
|
145
|
+
return {
|
|
146
|
+
nodes,
|
|
147
|
+
similarities: nodes.map(()=>1.0),
|
|
148
|
+
ids: (data || []).map((item)=>item.id)
|
|
149
|
+
};
|
|
150
|
+
}
|
|
105
151
|
/**
|
|
106
152
|
* Converts metadata filters to supabase query filter format
|
|
107
153
|
* @param queryFilters - Metadata filters to convert
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vectorstores/supabase",
|
|
3
3
|
"description": "Supabase Storage for vectorstores",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.6",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"vitest": "2.1.0",
|
|
38
|
-
"@vectorstores/core": "0.1.
|
|
38
|
+
"@vectorstores/core": "0.1.6",
|
|
39
39
|
"@vectorstores/env": "0.1.0"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@vectorstores/core": "0.1.
|
|
42
|
+
"@vectorstores/core": "0.1.6",
|
|
43
43
|
"@vectorstores/env": "0.1.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|