@miniaxolotl/grove 0.2.4 → 0.2.5

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +6 -6
  3. package/dist/config.d.ts.map +1 -1
  4. package/dist/config.js +8 -0
  5. package/dist/config.js.map +1 -1
  6. package/dist/index.js +253 -289
  7. package/dist/index.js.map +1 -1
  8. package/dist/repositories/entity.repository.d.ts.map +1 -1
  9. package/dist/repositories/entity.repository.js +24 -41
  10. package/dist/repositories/entity.repository.js.map +1 -1
  11. package/dist/repositories/memory.repository.d.ts +16 -21
  12. package/dist/repositories/memory.repository.d.ts.map +1 -1
  13. package/dist/repositories/memory.repository.js +71 -132
  14. package/dist/repositories/memory.repository.js.map +1 -1
  15. package/dist/repositories/relation.repository.d.ts.map +1 -1
  16. package/dist/repositories/relation.repository.js +25 -43
  17. package/dist/repositories/relation.repository.js.map +1 -1
  18. package/dist/services/embedding.d.ts +1 -0
  19. package/dist/services/embedding.d.ts.map +1 -1
  20. package/dist/services/embedding.js +8 -1
  21. package/dist/services/embedding.js.map +1 -1
  22. package/dist/services/qdrant.d.ts +5 -2
  23. package/dist/services/qdrant.d.ts.map +1 -1
  24. package/dist/services/qdrant.js +27 -10
  25. package/dist/services/qdrant.js.map +1 -1
  26. package/dist/utils/filter.d.ts +10 -0
  27. package/dist/utils/filter.d.ts.map +1 -0
  28. package/dist/utils/filter.js +15 -0
  29. package/dist/utils/filter.js.map +1 -0
  30. package/eslint.config.js +1 -1
  31. package/package.json +12 -12
  32. package/src/config.ts +5 -0
  33. package/src/index.ts +263 -336
  34. package/src/repositories/entity.repository.ts +30 -42
  35. package/src/repositories/memory.repository.ts +105 -166
  36. package/src/repositories/relation.repository.ts +33 -41
  37. package/src/services/embedding.ts +9 -1
  38. package/src/services/qdrant.ts +30 -13
  39. package/src/utils/filter.ts +20 -0
  40. package/tsconfig.json +1 -1
@@ -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
- if (!data.result.collections.some((c) => c.name === name)) {
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
- ): Promise<VectorPoint[]> {
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
- try {
140
- const data = (await qdrantFetch(
141
- "GET",
142
- `/collections/${collection}/points/${id}`,
143
- )) as { result: VectorPoint | null };
144
- return data.result;
145
- } catch {
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
+ }
package/tsconfig.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/tsconfig",
3
- "extends": "@grove/typescript-config/node.json",
3
+ "extends": "@lib/typescript-config/node.json",
4
4
  "compilerOptions": {
5
5
  "outDir": "./dist",
6
6
  "rootDir": "./src"