@miniaxolotl/grove 0.2.4 → 0.2.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/CHANGELOG.md +1 -1
- package/README.md +6 -6
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +9 -1
- package/dist/config.js.map +1 -1
- package/dist/index.js +260 -292
- package/dist/index.js.map +1 -1
- package/dist/repositories/entity.repository.d.ts.map +1 -1
- package/dist/repositories/entity.repository.js +24 -41
- package/dist/repositories/entity.repository.js.map +1 -1
- package/dist/repositories/memory.repository.d.ts +16 -35
- package/dist/repositories/memory.repository.d.ts.map +1 -1
- package/dist/repositories/memory.repository.js +71 -132
- package/dist/repositories/memory.repository.js.map +1 -1
- package/dist/repositories/relation.repository.d.ts.map +1 -1
- package/dist/repositories/relation.repository.js +25 -43
- package/dist/repositories/relation.repository.js.map +1 -1
- package/dist/services/embedding.d.ts +1 -0
- package/dist/services/embedding.d.ts.map +1 -1
- package/dist/services/embedding.js +8 -1
- package/dist/services/embedding.js.map +1 -1
- package/dist/services/qdrant.d.ts +5 -2
- package/dist/services/qdrant.d.ts.map +1 -1
- package/dist/services/qdrant.js +27 -10
- package/dist/services/qdrant.js.map +1 -1
- package/dist/utils/filter.d.ts +10 -0
- package/dist/utils/filter.d.ts.map +1 -0
- package/dist/utils/filter.js +15 -0
- package/dist/utils/filter.js.map +1 -0
- package/eslint.config.js +1 -1
- package/package.json +14 -13
- package/src/config.ts +6 -1
- package/src/index.ts +270 -339
- package/src/repositories/entity.repository.ts +30 -42
- package/src/repositories/memory.repository.ts +105 -181
- package/src/repositories/relation.repository.ts +33 -41
- package/src/services/embedding.ts +9 -1
- package/src/services/qdrant.ts +30 -13
- package/src/utils/filter.ts +20 -0
- package/tsconfig.json +1 -1
package/src/services/qdrant.ts
CHANGED
|
@@ -40,12 +40,14 @@ export interface SearchResult extends VectorPoint {
|
|
|
40
40
|
export async function ensureCollection(
|
|
41
41
|
name: string,
|
|
42
42
|
vectorDim: number = config.vector.dim,
|
|
43
|
+
indexFields: string[] = [],
|
|
43
44
|
): Promise<void> {
|
|
44
45
|
const data = (await qdrantFetch("GET", "/collections")) as {
|
|
45
46
|
result: { collections: { name: string }[] };
|
|
46
47
|
};
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
const exists = data.result.collections.some((c) => c.name === name);
|
|
50
|
+
if (!exists) {
|
|
49
51
|
await qdrantFetch("PUT", `/collections/${name}`, {
|
|
50
52
|
vectors: {
|
|
51
53
|
size: vectorDim,
|
|
@@ -53,6 +55,14 @@ export async function ensureCollection(
|
|
|
53
55
|
},
|
|
54
56
|
});
|
|
55
57
|
}
|
|
58
|
+
|
|
59
|
+
for (const field of indexFields) {
|
|
60
|
+
try {
|
|
61
|
+
await createIndex(name, field);
|
|
62
|
+
} catch (err) {
|
|
63
|
+
console.warn(`Failed to create index on '${name}.${field}':`, err);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
56
66
|
}
|
|
57
67
|
|
|
58
68
|
export async function createIndex(
|
|
@@ -114,18 +124,23 @@ export async function scrollPoints(
|
|
|
114
124
|
collection: string,
|
|
115
125
|
filter?: Record<string, unknown>,
|
|
116
126
|
limit: number = 100,
|
|
117
|
-
|
|
127
|
+
offset?: string,
|
|
128
|
+
): Promise<{ points: VectorPoint[]; nextPageOffset: string | null }> {
|
|
118
129
|
const body: Record<string, unknown> = { limit, with_payload: true };
|
|
119
130
|
if (filter) body.filter = filter;
|
|
131
|
+
if (offset) body.offset = offset;
|
|
120
132
|
|
|
121
133
|
const data = (await qdrantFetch(
|
|
122
134
|
"POST",
|
|
123
135
|
`/collections/${collection}/points/scroll`,
|
|
124
136
|
body,
|
|
125
137
|
)) as {
|
|
126
|
-
result: { points: VectorPoint[] };
|
|
138
|
+
result: { points: VectorPoint[]; next_page_offset: string | null };
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
points: data.result.points,
|
|
142
|
+
nextPageOffset: data.result.next_page_offset ?? null,
|
|
127
143
|
};
|
|
128
|
-
return data.result.points;
|
|
129
144
|
}
|
|
130
145
|
|
|
131
146
|
export async function deleteCollection(name: string): Promise<void> {
|
|
@@ -136,15 +151,16 @@ export async function getPoint(
|
|
|
136
151
|
collection: string,
|
|
137
152
|
id: string,
|
|
138
153
|
): Promise<VectorPoint | null> {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return null;
|
|
154
|
+
const url = `${config.qdrant.url}/collections/${collection}/points/${id}`;
|
|
155
|
+
const response = await fetch(url, { method: "GET", headers: QDRANT_HEADERS });
|
|
156
|
+
if (response.status === 404) return null;
|
|
157
|
+
if (!response.ok) {
|
|
158
|
+
throw new Error(
|
|
159
|
+
`Qdrant GET points/${id} failed: ${response.status} ${await response.text()}`,
|
|
160
|
+
);
|
|
147
161
|
}
|
|
162
|
+
const data = (await response.json()) as { result: VectorPoint | null };
|
|
163
|
+
return data.result;
|
|
148
164
|
}
|
|
149
165
|
|
|
150
166
|
export async function getCollectionInfo(name: string): Promise<{
|
|
@@ -165,7 +181,8 @@ export async function getCollectionInfo(name: string): Promise<{
|
|
|
165
181
|
pointsCount: data.result.points_count,
|
|
166
182
|
indexedVectorsCount: data.result.indexed_vectors_count,
|
|
167
183
|
};
|
|
168
|
-
} catch {
|
|
184
|
+
} catch (err) {
|
|
185
|
+
console.warn(`Failed to get collection info for '${name}':`, err);
|
|
169
186
|
return null;
|
|
170
187
|
}
|
|
171
188
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type Condition =
|
|
2
|
+
| { key: string; value: string }
|
|
3
|
+
| { key: string; any: string[] }
|
|
4
|
+
| undefined
|
|
5
|
+
| null;
|
|
6
|
+
|
|
7
|
+
export function buildFilter(
|
|
8
|
+
conditions: Condition[],
|
|
9
|
+
): Record<string, unknown> | undefined {
|
|
10
|
+
const must: Record<string, unknown>[] = [];
|
|
11
|
+
for (const cond of conditions) {
|
|
12
|
+
if (!cond) continue;
|
|
13
|
+
if ("value" in cond) {
|
|
14
|
+
must.push({ key: cond.key, match: { value: cond.value } });
|
|
15
|
+
} else if (cond.any.length > 0) {
|
|
16
|
+
must.push({ key: cond.key, match: { any: cond.any } });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return must.length > 0 ? { must } : undefined;
|
|
20
|
+
}
|