@o-lang/semantic-doc-search 1.0.14 → 1.0.15
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/package.json
CHANGED
|
@@ -13,35 +13,26 @@ class PgVectorAdapter {
|
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
// Convert JavaScript array to PostgreSQL array format
|
|
17
|
-
// [1.0, 2.0, 3.0] -> {1.0,2.0,3.0}
|
|
18
|
-
arrayToPgArray(arr) {
|
|
19
|
-
return `{${arr.join(',')}}`;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
16
|
async upsert({ id, vector, content, source, metadata = {} }) {
|
|
23
|
-
//
|
|
24
|
-
const pgVector = this.arrayToPgArray(vector);
|
|
25
|
-
|
|
17
|
+
// Pass vector as array parameter - let pg handle conversion
|
|
26
18
|
await this.pool.query(
|
|
27
19
|
`INSERT INTO doc_embeddings (id, embedding, content, source, metadata)
|
|
28
20
|
VALUES ($1, $2::vector, $3, $4, $5::jsonb)
|
|
29
21
|
ON CONFLICT (id) DO UPDATE
|
|
30
22
|
SET embedding = $2::vector, content = $3, source = $4, metadata = $5::jsonb, updated_at = NOW()`,
|
|
31
|
-
[id,
|
|
23
|
+
[id, vector, content, source, JSON.stringify(metadata)]
|
|
32
24
|
);
|
|
33
25
|
}
|
|
34
26
|
|
|
35
27
|
async query(vector, topK = 5) {
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
// Pass vector as array parameter - let pg handle conversion
|
|
38
29
|
const res = await this.pool.query(
|
|
39
30
|
`SELECT id, content, source, metadata,
|
|
40
31
|
1 - (embedding <=> $1::vector) AS score
|
|
41
32
|
FROM doc_embeddings
|
|
42
33
|
ORDER BY embedding <=> $1::vector
|
|
43
34
|
LIMIT $2`,
|
|
44
|
-
[
|
|
35
|
+
[vector, topK]
|
|
45
36
|
);
|
|
46
37
|
|
|
47
38
|
return res.rows.map(row => ({
|