@thenajs/qdrant-client 0.6.0 → 0.10.0
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 +1 -1
- package/dist/qdrant.store.d.ts +3 -3
- package/dist/qdrant.store.d.ts.map +1 -1
- package/dist/qdrant.store.js +21 -21
- package/dist/qdrant.store.js.map +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
package/dist/qdrant.store.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare class QdrantStore extends VectorStore {
|
|
|
31
31
|
* apenas a forma abreviada é aceita, então caímos para ela: o índice sai
|
|
32
32
|
* igual, só sem a otimização de co-locação.
|
|
33
33
|
*/
|
|
34
|
-
private
|
|
34
|
+
private createPartitionIndex;
|
|
35
35
|
collectionExists(): Promise<boolean>;
|
|
36
36
|
dropCollection(): Promise<void>;
|
|
37
37
|
upsert(docs: VectorDocument[]): Promise<void>;
|
|
@@ -42,8 +42,8 @@ export declare class QdrantStore extends VectorStore {
|
|
|
42
42
|
* `rawFilter` vence quando presente — é o escape hatch para o que a
|
|
43
43
|
* igualdade não cobre (ranges, geo, aninhamento).
|
|
44
44
|
*/
|
|
45
|
-
private
|
|
45
|
+
private buildFilter;
|
|
46
46
|
/** Uma chamada à API, já com auth, retry e a mensagem de erro do Qdrant. */
|
|
47
|
-
private
|
|
47
|
+
private call;
|
|
48
48
|
}
|
|
49
49
|
//# sourceMappingURL=qdrant.store.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qdrant.store.d.ts","sourceRoot":"","sources":["../src/qdrant.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"qdrant.store.d.ts","sourceRoot":"","sources":["../src/qdrant.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,KAAK,EACV,iBAAiB,EAEjB,cAAc,EACd,WAAW,EACX,YAAY,EACZ,cAAc,EACd,sBAAsB,EACvB,MAAM,eAAe,CAAC;AAEvB,MAAM,MAAM,iBAAiB,GAAG,sBAAsB,CAAC;AAUvD;;;;;;;;;;;;GAYG;AACH,qBAAa,WAAY,SAAQ,WAAW;IAC1C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,iEAAiE;IACjE,SAAgB,YAAY,EAAE,MAAM,CAAC;gBAEzB,WAAW,EAAE,iBAAiB;IASpC,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAajE;;;;;;;;OAQG;YACW,oBAAoB;IAgB5B,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAAC;IAQpC,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAI/B,MAAM,CAAC,IAAI,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAY7C,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAkBpD,MAAM,CAAC,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBrD;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAYnB,4EAA4E;YAC9D,IAAI;CAuBnB"}
|
package/dist/qdrant.store.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { VectorStore } from "@thenajs/core";
|
|
2
2
|
/** O shape neutro de distância → o nome que o Qdrant espera. */
|
|
3
|
-
const
|
|
3
|
+
const DISTANCES = {
|
|
4
4
|
cosine: "Cosine",
|
|
5
5
|
euclid: "Euclid",
|
|
6
6
|
dot: "Dot",
|
|
@@ -36,13 +36,13 @@ export class QdrantStore extends VectorStore {
|
|
|
36
36
|
async ensureCollection(options) {
|
|
37
37
|
if (await this.collectionExists())
|
|
38
38
|
return;
|
|
39
|
-
await this.
|
|
39
|
+
await this.call(`/collections/${this.collection}`, "PUT", {
|
|
40
40
|
vectors: {
|
|
41
41
|
size: options.size,
|
|
42
|
-
distance:
|
|
42
|
+
distance: DISTANCES[options.distance ?? "cosine"],
|
|
43
43
|
},
|
|
44
44
|
});
|
|
45
|
-
await this.
|
|
45
|
+
await this.createPartitionIndex();
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Índice no campo que particiona os datasets.
|
|
@@ -53,33 +53,33 @@ export class QdrantStore extends VectorStore {
|
|
|
53
53
|
* apenas a forma abreviada é aceita, então caímos para ela: o índice sai
|
|
54
54
|
* igual, só sem a otimização de co-locação.
|
|
55
55
|
*/
|
|
56
|
-
async
|
|
56
|
+
async createPartitionIndex() {
|
|
57
57
|
const rota = `/collections/${this.collection}/index?wait=true`;
|
|
58
58
|
try {
|
|
59
|
-
await this.
|
|
59
|
+
await this.call(rota, "PUT", {
|
|
60
60
|
field_name: this.datasetField,
|
|
61
61
|
field_schema: { type: "keyword", is_tenant: true },
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
64
|
catch {
|
|
65
65
|
// Se a forma abreviada também falhar, aí é problema de verdade e sobe.
|
|
66
|
-
await this.
|
|
66
|
+
await this.call(rota, "PUT", {
|
|
67
67
|
field_name: this.datasetField,
|
|
68
68
|
field_schema: "keyword",
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
async collectionExists() {
|
|
73
|
-
const data = await this.
|
|
73
|
+
const data = await this.call(`/collections/${this.collection}/exists`, "GET");
|
|
74
74
|
return Boolean(data?.result?.exists);
|
|
75
75
|
}
|
|
76
76
|
async dropCollection() {
|
|
77
|
-
await this.
|
|
77
|
+
await this.call(`/collections/${this.collection}`, "DELETE");
|
|
78
78
|
}
|
|
79
79
|
async upsert(docs) {
|
|
80
80
|
if (!docs.length)
|
|
81
81
|
return;
|
|
82
|
-
await this.
|
|
82
|
+
await this.call(`/collections/${this.collection}/points?wait=true`, "PUT", {
|
|
83
83
|
points: docs.map((d) => ({
|
|
84
84
|
id: d.id,
|
|
85
85
|
vector: d.vector,
|
|
@@ -88,10 +88,10 @@ export class QdrantStore extends VectorStore {
|
|
|
88
88
|
});
|
|
89
89
|
}
|
|
90
90
|
async search(params) {
|
|
91
|
-
const data = await this.
|
|
91
|
+
const data = await this.call(`/collections/${this.collection}/points/query`, "POST", {
|
|
92
92
|
query: params.vector,
|
|
93
93
|
limit: params.limit ?? 5,
|
|
94
|
-
filter: this.
|
|
94
|
+
filter: this.buildFilter(params.where, params.rawFilter),
|
|
95
95
|
with_payload: params.withPayload ?? true,
|
|
96
96
|
score_threshold: params.scoreThreshold,
|
|
97
97
|
});
|
|
@@ -102,23 +102,23 @@ export class QdrantStore extends VectorStore {
|
|
|
102
102
|
}));
|
|
103
103
|
}
|
|
104
104
|
async remove(selector) {
|
|
105
|
-
const filter = this.
|
|
106
|
-
const
|
|
105
|
+
const filter = this.buildFilter(selector.where);
|
|
106
|
+
const body = selector.ids?.length
|
|
107
107
|
? { points: selector.ids }
|
|
108
108
|
: filter
|
|
109
109
|
? { filter }
|
|
110
110
|
: undefined;
|
|
111
111
|
// Sem seletor nenhum, apagar tudo seria destrutivo demais para ser implícito.
|
|
112
|
-
if (!
|
|
112
|
+
if (!body)
|
|
113
113
|
return;
|
|
114
|
-
await this.
|
|
114
|
+
await this.call(`/collections/${this.collection}/points/delete?wait=true`, "POST", body);
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
117
117
|
* Traduz o `where` neutro (igualdade) para o formato do Qdrant. O
|
|
118
118
|
* `rawFilter` vence quando presente — é o escape hatch para o que a
|
|
119
119
|
* igualdade não cobre (ranges, geo, aninhamento).
|
|
120
120
|
*/
|
|
121
|
-
|
|
121
|
+
buildFilter(where, rawFilter) {
|
|
122
122
|
if (rawFilter !== undefined)
|
|
123
123
|
return rawFilter;
|
|
124
124
|
if (!where || !Object.keys(where).length)
|
|
@@ -131,8 +131,8 @@ export class QdrantStore extends VectorStore {
|
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
133
|
/** Uma chamada à API, já com auth, retry e a mensagem de erro do Qdrant. */
|
|
134
|
-
async
|
|
135
|
-
const { response } = await this.request(`${this.url}${
|
|
134
|
+
async call(path, method, body) {
|
|
135
|
+
const { response } = await this.request(`${this.url}${path}`, {
|
|
136
136
|
method,
|
|
137
137
|
headers: {
|
|
138
138
|
"Content-Type": "application/json",
|
|
@@ -141,8 +141,8 @@ export class QdrantStore extends VectorStore {
|
|
|
141
141
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
142
142
|
});
|
|
143
143
|
if (!response.ok) {
|
|
144
|
-
const
|
|
145
|
-
throw new Error(`Qdrant ${method} ${
|
|
144
|
+
const detail = await response.text();
|
|
145
|
+
throw new Error(`Qdrant ${method} ${path} failed (${response.status}): ${detail}`);
|
|
146
146
|
}
|
|
147
147
|
return (await response.json());
|
|
148
148
|
}
|
package/dist/qdrant.store.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qdrant.store.js","sourceRoot":"","sources":["../src/qdrant.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"qdrant.store.js","sourceRoot":"","sources":["../src/qdrant.store.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAa5C,gEAAgE;AAChE,MAAM,SAAS,GAAmC;IAChD,MAAM,EAAE,QAAQ;IAChB,MAAM,EAAE,QAAQ;IAChB,GAAG,EAAE,KAAK;IACV,SAAS,EAAE,WAAW;CACvB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,WAAY,SAAQ,WAAW;IACzB,GAAG,CAAS;IACZ,MAAM,CAAU;IAChB,UAAU,CAAS;IACpC,iEAAiE;IACjD,YAAY,CAAS;I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;IACJ,CAAC;IAED,4EAA4E;IACpE,KAAK,CAAC,IAAI,CAChB,IAAY,EACZ,MAAc,EACd,IAAc;QAEd,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,GAAG,GAAG,IAAI,EAAE,EAAE;YAC5D,MAAM;YACN,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACnD;YACD,IAAI,EAAE,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC5D,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CACb,UAAU,MAAM,IAAI,IAAI,YAAY,QAAQ,CAAC,MAAM,MAAM,MAAM,EAAE,CAClE,CAAC;QACJ,CAAC;QAED,OAAO,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAM,CAAC;IACtC,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thenajs/qdrant-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Cliente Qdrant nativo para ThenaJS \u2014 implementa\u00e7\u00e3o de VectorStore sobre a API REST, sem SDK.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "castroneto",
|
|
@@ -30,7 +30,10 @@
|
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|
|
32
32
|
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=20.19"
|
|
35
|
+
},
|
|
33
36
|
"dependencies": {
|
|
34
|
-
"@thenajs/core": "^0.
|
|
37
|
+
"@thenajs/core": "^0.10.0"
|
|
35
38
|
}
|
|
36
39
|
}
|