@miniaxolotl/grove 0.3.1 → 0.6.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.
Files changed (59) hide show
  1. package/README.md +15 -107
  2. package/dist/bridge.js +30615 -0
  3. package/dist/bridge.js.map +7 -0
  4. package/dist/cli.js +32893 -34
  5. package/dist/cli.js.map +7 -1
  6. package/dist/hook.js +15716 -0
  7. package/dist/hook.js.map +7 -0
  8. package/dist/index.js +29254 -490
  9. package/dist/index.js.map +7 -1
  10. package/package.json +22 -17
  11. package/CHANGELOG.md +0 -62
  12. package/dist/cli.d.ts +0 -2
  13. package/dist/cli.d.ts.map +0 -1
  14. package/dist/config.d.ts +0 -27
  15. package/dist/config.d.ts.map +0 -1
  16. package/dist/config.js +0 -35
  17. package/dist/config.js.map +0 -1
  18. package/dist/index.d.ts +0 -2
  19. package/dist/index.d.ts.map +0 -1
  20. package/dist/repositories/entity.repository.d.ts +0 -44
  21. package/dist/repositories/entity.repository.d.ts.map +0 -1
  22. package/dist/repositories/entity.repository.js +0 -186
  23. package/dist/repositories/entity.repository.js.map +0 -1
  24. package/dist/repositories/memory.repository.d.ts +0 -59
  25. package/dist/repositories/memory.repository.d.ts.map +0 -1
  26. package/dist/repositories/memory.repository.js +0 -222
  27. package/dist/repositories/memory.repository.js.map +0 -1
  28. package/dist/repositories/relation.repository.d.ts +0 -38
  29. package/dist/repositories/relation.repository.d.ts.map +0 -1
  30. package/dist/repositories/relation.repository.js +0 -95
  31. package/dist/repositories/relation.repository.js.map +0 -1
  32. package/dist/services/embedding.d.ts +0 -4
  33. package/dist/services/embedding.d.ts.map +0 -1
  34. package/dist/services/embedding.js +0 -114
  35. package/dist/services/embedding.js.map +0 -1
  36. package/dist/services/qdrant.d.ts +0 -38
  37. package/dist/services/qdrant.d.ts.map +0 -1
  38. package/dist/services/qdrant.js +0 -117
  39. package/dist/services/qdrant.js.map +0 -1
  40. package/dist/services/reranking.d.ts +0 -6
  41. package/dist/services/reranking.d.ts.map +0 -1
  42. package/dist/services/reranking.js +0 -24
  43. package/dist/services/reranking.js.map +0 -1
  44. package/dist/utils/filter.d.ts +0 -10
  45. package/dist/utils/filter.d.ts.map +0 -1
  46. package/dist/utils/filter.js +0 -15
  47. package/dist/utils/filter.js.map +0 -1
  48. package/eslint.config.js +0 -1
  49. package/src/cli.ts +0 -37
  50. package/src/config.ts +0 -32
  51. package/src/index.ts +0 -594
  52. package/src/repositories/entity.repository.ts +0 -253
  53. package/src/repositories/memory.repository.ts +0 -316
  54. package/src/repositories/relation.repository.ts +0 -143
  55. package/src/services/embedding.ts +0 -150
  56. package/src/services/qdrant.ts +0 -201
  57. package/src/services/reranking.ts +0 -40
  58. package/src/utils/filter.ts +0 -20
  59. package/tsconfig.json +0 -10
@@ -1,253 +0,0 @@
1
- import { randomUUID } from "crypto";
2
- import { config } from "../config.ts";
3
- import { qdrant } from "../services/qdrant.ts";
4
- import { buildFilter } from "../utils/filter.ts";
5
-
6
- const COLLECTION = `${config.collection.prefix}_entities`;
7
-
8
- export interface Entity {
9
- id: string;
10
- name: string;
11
- entityType: string;
12
- observations: string[];
13
- metadata?: Record<string, unknown>;
14
- }
15
-
16
- export async function createEntity(
17
- name: string,
18
- entityType: string,
19
- observations: string[] = [],
20
- metadata?: Record<string, unknown>,
21
- ): Promise<Entity> {
22
- const existing = await getEntity(name);
23
- if (existing) {
24
- const mergedObservations = [
25
- ...existing.observations,
26
- ...observations.filter((o) => !existing.observations.includes(o)),
27
- ];
28
- const mergedMetadata = { ...existing.metadata, ...metadata };
29
-
30
- await qdrant.upsertPoints(COLLECTION, [
31
- {
32
- id: existing.id,
33
- vector: Array(config.vector.dim).fill(0),
34
- payload: {
35
- id: existing.id,
36
- name,
37
- entityType,
38
- observations: mergedObservations,
39
- metadata: mergedMetadata,
40
- },
41
- },
42
- ]);
43
-
44
- return {
45
- id: existing.id,
46
- name,
47
- entityType,
48
- observations: mergedObservations,
49
- metadata: mergedMetadata,
50
- };
51
- }
52
-
53
- const id = randomUUID();
54
- const point = {
55
- id,
56
- vector: Array(config.vector.dim).fill(0),
57
- payload: { id, name, entityType, observations, metadata },
58
- };
59
-
60
- await qdrant.upsertPoints(COLLECTION, [point]);
61
-
62
- return { id, name, entityType, observations, metadata };
63
- }
64
-
65
- export async function getEntity(name: string): Promise<Entity | null> {
66
- const { points } = await qdrant.scrollPoints(COLLECTION, {
67
- must: [{ key: "name", match: { value: name } }],
68
- });
69
-
70
- if (points.length === 0) return null;
71
-
72
- const p = points[0];
73
- return {
74
- id: p.id,
75
- name: p.payload.name as string,
76
- entityType: p.payload.entityType as string,
77
- observations: (p.payload.observations as string[]) ?? [],
78
- metadata: p.payload.metadata as Record<string, unknown> | undefined,
79
- };
80
- }
81
-
82
- export async function searchEntities(
83
- query?: string,
84
- entityType?: string,
85
- limit: number = 10,
86
- ): Promise<Entity[]> {
87
- const filter = buildFilter([
88
- query ? { key: "name", value: query } : null,
89
- entityType ? { key: "entityType", value: entityType } : null,
90
- ]);
91
- const { points } = await qdrant.scrollPoints(COLLECTION, filter, limit);
92
-
93
- return points.map((p) => ({
94
- id: p.id,
95
- name: p.payload.name as string,
96
- entityType: p.payload.entityType as string,
97
- observations: (p.payload.observations as string[]) ?? [],
98
- metadata: p.payload.metadata as Record<string, unknown> | undefined,
99
- }));
100
- }
101
-
102
- export async function addObservations(
103
- name: string,
104
- newObservations: string[],
105
- ): Promise<Entity | null> {
106
- const entity = await getEntity(name);
107
- if (!entity) return null;
108
-
109
- const updated = {
110
- ...entity,
111
- observations: Array.from(new Set([...entity.observations, ...newObservations])),
112
- };
113
-
114
- await qdrant.upsertPoints(COLLECTION, [
115
- {
116
- id: entity.id,
117
- vector: Array(config.vector.dim).fill(0),
118
- payload: {
119
- id: updated.id,
120
- name: updated.name,
121
- entityType: updated.entityType,
122
- observations: updated.observations,
123
- metadata: updated.metadata,
124
- },
125
- },
126
- ]);
127
-
128
- return updated;
129
- }
130
-
131
- export async function deleteEntities(
132
- filter: {
133
- name?: string;
134
- entityType?: string;
135
- } = {},
136
- ): Promise<void> {
137
- const qdrantFilter = buildFilter([
138
- filter.name ? { key: "name", value: filter.name } : null,
139
- filter.entityType ? { key: "entityType", value: filter.entityType } : null,
140
- ]);
141
- if (!qdrantFilter) return;
142
-
143
- await qdrant.deleteByFilter(COLLECTION, qdrantFilter);
144
- }
145
-
146
- export async function getEntityById(id: string): Promise<Entity | null> {
147
- const point = await qdrant.getPoint(COLLECTION, id);
148
- if (!point) return null;
149
- return {
150
- id: point.id,
151
- name: point.payload.name as string,
152
- entityType: point.payload.entityType as string,
153
- observations: (point.payload.observations as string[]) ?? [],
154
- metadata: point.payload.metadata as Record<string, unknown> | undefined,
155
- };
156
- }
157
-
158
- export async function updateEntity(
159
- id: string,
160
- updates: {
161
- name?: string;
162
- entityType?: string;
163
- metadata?: Record<string, unknown>;
164
- },
165
- ): Promise<Entity | null> {
166
- const existing = await getEntityById(id);
167
- if (!existing) return null;
168
-
169
- const updated: Entity = {
170
- ...existing,
171
- name: updates.name ?? existing.name,
172
- entityType: updates.entityType ?? existing.entityType,
173
- metadata: updates.metadata ?? existing.metadata,
174
- };
175
-
176
- await qdrant.upsertPoints(COLLECTION, [
177
- {
178
- id,
179
- vector: Array(config.vector.dim).fill(0),
180
- payload: {
181
- id,
182
- name: updated.name,
183
- entityType: updated.entityType,
184
- observations: updated.observations,
185
- metadata: updated.metadata,
186
- },
187
- },
188
- ]);
189
-
190
- return updated;
191
- }
192
-
193
- export async function getEntityStats(): Promise<{
194
- count: number;
195
- vectorsCount: number;
196
- indexedVectorsCount: number;
197
- }> {
198
- const info = await qdrant.getCollectionInfo(COLLECTION);
199
- if (!info) return { count: 0, vectorsCount: 0, indexedVectorsCount: 0 };
200
- return {
201
- count: info.pointsCount,
202
- vectorsCount: info.vectorsCount,
203
- indexedVectorsCount: info.indexedVectorsCount,
204
- };
205
- }
206
-
207
- export async function listEntities(
208
- entityType?: string,
209
- limit: number = 100,
210
- offset?: string,
211
- ): Promise<{ entities: Entity[]; offset: string | null }> {
212
- const filter = buildFilter([
213
- entityType ? { key: "entityType", value: entityType } : null,
214
- ]);
215
-
216
- const { points, nextPageOffset } = await qdrant.scrollPoints(
217
- COLLECTION,
218
- filter,
219
- limit,
220
- offset,
221
- );
222
-
223
- return {
224
- entities: points.map((p) => ({
225
- id: p.id,
226
- name: p.payload.name as string,
227
- entityType: p.payload.entityType as string,
228
- observations: (p.payload.observations as string[]) ?? [],
229
- metadata: p.payload.metadata as Record<string, unknown> | undefined,
230
- })),
231
- offset: nextPageOffset,
232
- };
233
- }
234
-
235
- export async function initEntityCollection(): Promise<void> {
236
- await qdrant.ensureCollection(COLLECTION, config.vector.dim, [
237
- "name",
238
- "entityType",
239
- ]);
240
- }
241
-
242
- export const entityRepository = {
243
- create: createEntity,
244
- get: getEntity,
245
- search: searchEntities,
246
- addObservations,
247
- delete: deleteEntities,
248
- init: initEntityCollection,
249
- getById: getEntityById,
250
- update: updateEntity,
251
- stats: getEntityStats,
252
- list: listEntities,
253
- };
@@ -1,316 +0,0 @@
1
- import { randomUUID } from "crypto";
2
- import { config } from "../config.ts";
3
- import { qdrant, type VectorPoint } from "../services/qdrant.ts";
4
- import { buildFilter } from "../utils/filter.ts";
5
- import type { Memory, MemorySearchResult } from "@lib/shared";
6
-
7
- const COLLECTION = `${config.collection.prefix}_memories`;
8
-
9
- export type { Memory, MemorySearchResult };
10
-
11
- let _embedTexts: ((texts: string[]) => Promise<number[][]>) | null = null;
12
-
13
- async function getEmbedTexts(): Promise<
14
- ((texts: string[]) => Promise<number[][]>) | null
15
- > {
16
- if (_embedTexts === null) {
17
- try {
18
- const { embedTexts } = await import("../services/embedding.ts");
19
- _embedTexts = embedTexts;
20
- } catch {
21
- _embedTexts = null;
22
- }
23
- }
24
- return _embedTexts;
25
- }
26
-
27
- export async function saveMemory(
28
- text: string,
29
- metadata: Partial<Memory["metadata"]> = {},
30
- ): Promise<Memory> {
31
- const id = randomUUID();
32
- const embedFn = await getEmbedTexts();
33
-
34
- let vector: number[];
35
- if (embedFn) {
36
- [vector] = await embedFn([text]);
37
- } else {
38
- vector = Array(config.vector.dim).fill(0);
39
- }
40
-
41
- const point: VectorPoint = {
42
- id,
43
- vector,
44
- payload: {
45
- id,
46
- text,
47
- metadata: {
48
- ...metadata,
49
- createdAt: metadata.createdAt ?? new Date().toISOString(),
50
- },
51
- },
52
- };
53
-
54
- await qdrant.upsertPoints(COLLECTION, [point]);
55
-
56
- return { id, text, metadata: point.payload.metadata as Memory["metadata"] };
57
- }
58
-
59
- export async function searchMemories(
60
- query: string,
61
- options: {
62
- project?: string;
63
- tags?: string[];
64
- limit?: number;
65
- } = {},
66
- ): Promise<MemorySearchResult[]> {
67
- const limit = options.limit ?? 5;
68
- const embedFn = await getEmbedTexts();
69
-
70
- if (!embedFn) {
71
- const filter = buildFilter([
72
- options.project ? { key: "metadata.project", value: options.project } : null,
73
- options.tags?.length ? { key: "metadata.tags", any: options.tags } : null,
74
- ]);
75
- const { points } = await qdrant.scrollPoints(COLLECTION, filter, limit);
76
- return points.map((r) => ({
77
- id: r.id,
78
- text: r.payload.text as string,
79
- metadata: r.payload.metadata as Memory["metadata"],
80
- score: 0,
81
- }));
82
- }
83
-
84
- const [queryVector] = await embedFn([query]);
85
-
86
- const filter = buildFilter([
87
- options.project ? { key: "metadata.project", value: options.project } : null,
88
- options.tags?.length ? { key: "metadata.tags", any: options.tags } : null,
89
- ]);
90
-
91
- const results = await qdrant.searchVectors(
92
- COLLECTION,
93
- queryVector,
94
- limit,
95
- filter,
96
- );
97
-
98
- return results.map((r) => ({
99
- id: r.id,
100
- text: r.payload.text as string,
101
- metadata: r.payload.metadata as Memory["metadata"],
102
- score: r.score ?? 0,
103
- }));
104
- }
105
-
106
- export async function deleteMemories(ids: string[]): Promise<void> {
107
- await qdrant.deletePoints(COLLECTION, ids);
108
- }
109
-
110
- export async function deleteMemoriesByFilter(filter: {
111
- project?: string;
112
- tags?: string[];
113
- }): Promise<void> {
114
- const qdrantFilter = buildFilter([
115
- filter.project ? { key: "metadata.project", value: filter.project } : null,
116
- filter.tags?.length ? { key: "metadata.tags", any: filter.tags } : null,
117
- ]);
118
- if (!qdrantFilter) return;
119
-
120
- await qdrant.deleteByFilter(COLLECTION, qdrantFilter);
121
- }
122
-
123
- export async function getMemoryById(id: string): Promise<Memory | null> {
124
- const point = await qdrant.getPoint(COLLECTION, id);
125
- if (!point) return null;
126
- return {
127
- id: point.id,
128
- text: point.payload.text as string,
129
- metadata: point.payload.metadata as Memory["metadata"],
130
- };
131
- }
132
-
133
- export async function updateMemory(
134
- id: string,
135
- updates: { text?: string; metadata?: Partial<Memory["metadata"]> },
136
- ): Promise<Memory | null> {
137
- const existing = await getMemoryById(id);
138
- if (!existing) return null;
139
-
140
- const updated: Memory = {
141
- ...existing,
142
- text: updates.text ?? existing.text,
143
- metadata: {
144
- ...existing.metadata,
145
- ...updates.metadata,
146
- updatedAt: new Date().toISOString(),
147
- },
148
- };
149
-
150
- let vector: number[];
151
- if (updates.text !== undefined) {
152
- const embedFn = await getEmbedTexts();
153
- if (embedFn) {
154
- [vector] = await embedFn([updated.text]);
155
- } else {
156
- vector = Array(config.vector.dim).fill(0);
157
- }
158
- } else {
159
- const point = await qdrant.getPoint(COLLECTION, id);
160
- vector = point?.vector ?? Array(config.vector.dim).fill(0);
161
- }
162
-
163
- await qdrant.upsertPoints(COLLECTION, [
164
- {
165
- id,
166
- vector,
167
- payload: { id, text: updated.text, metadata: updated.metadata },
168
- },
169
- ]);
170
-
171
- return updated;
172
- }
173
-
174
- export async function scrollMemories(
175
- options: {
176
- project?: string;
177
- tags?: string[];
178
- limit?: number;
179
- offset?: string;
180
- } = {},
181
- ): Promise<{ memories: Memory[]; offset: string | null }> {
182
- const limit = options.limit ?? 100;
183
- const filter = buildFilter([
184
- options.project ? { key: "metadata.project", value: options.project } : null,
185
- options.tags?.length ? { key: "metadata.tags", any: options.tags } : null,
186
- ]);
187
-
188
- const { points, nextPageOffset } = await qdrant.scrollPoints(
189
- COLLECTION,
190
- filter,
191
- limit,
192
- options.offset,
193
- );
194
-
195
- const memories: Memory[] = points.map((p) => ({
196
- id: p.id,
197
- text: p.payload.text as string,
198
- metadata: p.payload.metadata as Memory["metadata"],
199
- }));
200
-
201
- return {
202
- memories,
203
- offset: nextPageOffset,
204
- };
205
- }
206
-
207
- export async function getMemoriesStats(): Promise<{
208
- count: number;
209
- vectorsCount: number;
210
- indexedVectorsCount: number;
211
- }> {
212
- const info = await qdrant.getCollectionInfo(COLLECTION);
213
- if (!info) return { count: 0, vectorsCount: 0, indexedVectorsCount: 0 };
214
- return {
215
- count: info.pointsCount,
216
- vectorsCount: info.vectorsCount,
217
- indexedVectorsCount: info.indexedVectorsCount,
218
- };
219
- }
220
-
221
- export async function compactMemories(options: {
222
- project?: string;
223
- sessionId?: string;
224
- importanceThreshold?: number;
225
- }): Promise<{ compacted: number }> {
226
- const threshold = options.importanceThreshold ?? 0.6;
227
- const filter = buildFilter([
228
- options.project ? { key: "metadata.project", value: options.project } : null,
229
- options.sessionId ? { key: "metadata.sessionId", value: options.sessionId } : null,
230
- ]);
231
-
232
- let offset: string | null = null;
233
- let deleted = 0;
234
-
235
- do {
236
- const { points, nextPageOffset } = await qdrant.scrollPoints(
237
- COLLECTION,
238
- filter,
239
- 100,
240
- offset ?? undefined,
241
- );
242
-
243
- const toDelete = points
244
- .filter((p) => {
245
- const imp = (p.payload.metadata as Memory["metadata"])?.importance;
246
- return imp !== undefined && imp < threshold;
247
- })
248
- .map((p) => p.id);
249
-
250
- if (toDelete.length > 0) {
251
- await qdrant.deletePoints(COLLECTION, toDelete);
252
- deleted += toDelete.length;
253
- }
254
-
255
- offset = nextPageOffset;
256
- } while (offset !== null);
257
-
258
- return { compacted: deleted };
259
- }
260
-
261
- export async function pruneMemories(options: {
262
- threshold: number;
263
- project?: string;
264
- }): Promise<{ pruned: number }> {
265
- const filter = buildFilter([
266
- options.project ? { key: "metadata.project", value: options.project } : null,
267
- ]);
268
-
269
- let offset: string | null = null;
270
- let deleted = 0;
271
-
272
- do {
273
- const { points, nextPageOffset } = await qdrant.scrollPoints(
274
- COLLECTION,
275
- filter,
276
- 100,
277
- offset ?? undefined,
278
- );
279
-
280
- const toDelete = points
281
- .filter((p) => {
282
- const imp = (p.payload.metadata as Memory["metadata"])?.importance;
283
- return imp !== undefined && imp < options.threshold;
284
- })
285
- .map((p) => p.id);
286
-
287
- if (toDelete.length > 0) {
288
- await qdrant.deletePoints(COLLECTION, toDelete);
289
- deleted += toDelete.length;
290
- }
291
-
292
- offset = nextPageOffset;
293
- } while (offset !== null);
294
-
295
- return { pruned: deleted };
296
- }
297
-
298
- export async function initMemoryCollection(): Promise<void> {
299
- await qdrant.ensureCollection(COLLECTION, config.vector.dim, [
300
- "metadata.project",
301
- "metadata.tags",
302
- ]);
303
- }
304
-
305
- export const memoryRepository = {
306
- save: saveMemory,
307
- search: searchMemories,
308
- delete: deleteMemories,
309
- deleteByFilter: deleteMemoriesByFilter,
310
- init: initMemoryCollection,
311
- update: updateMemory,
312
- scroll: scrollMemories,
313
- stats: getMemoriesStats,
314
- compact: compactMemories,
315
- prune: pruneMemories,
316
- };
@@ -1,143 +0,0 @@
1
- import { randomUUID } from "crypto";
2
- import { config } from "../config.ts";
3
- import { qdrant } from "../services/qdrant.ts";
4
- import { buildFilter } from "../utils/filter.ts";
5
-
6
- const COLLECTION = `${config.collection.prefix}_relations`;
7
-
8
- export interface Relation {
9
- id: string;
10
- from: string;
11
- relationType: string;
12
- to: string;
13
- metadata?: Record<string, unknown>;
14
- }
15
-
16
- export async function createRelation(
17
- from: string,
18
- relationType: string,
19
- to: string,
20
- metadata?: Record<string, unknown>,
21
- ): Promise<Relation> {
22
- const existing = await searchRelations({ from, relationType, to, limit: 1 }, 1);
23
- if (existing.length > 0) {
24
- const rel = existing[0];
25
- const mergedMetadata = { ...rel.metadata, ...metadata };
26
-
27
- await qdrant.upsertPoints(COLLECTION, [
28
- {
29
- id: rel.id,
30
- vector: Array(config.vector.dim).fill(0),
31
- payload: { id: rel.id, from, relationType, to, metadata: mergedMetadata },
32
- },
33
- ]);
34
-
35
- return { id: rel.id, from, relationType, to, metadata: mergedMetadata };
36
- }
37
-
38
- const id = randomUUID();
39
- const point = {
40
- id,
41
- vector: Array(config.vector.dim).fill(0),
42
- payload: { id, from, relationType, to, metadata },
43
- };
44
-
45
- await qdrant.upsertPoints(COLLECTION, [point]);
46
-
47
- return { id, from, relationType, to, metadata };
48
- }
49
-
50
- export async function searchRelations(
51
- options: {
52
- from?: string;
53
- to?: string;
54
- relationType?: string;
55
- limit?: number;
56
- } = {},
57
- defaultLimit: number = 20,
58
- ): Promise<Relation[]> {
59
- const filter = buildFilter([
60
- options.from ? { key: "from", value: options.from } : null,
61
- options.to ? { key: "to", value: options.to } : null,
62
- options.relationType ? { key: "relationType", value: options.relationType } : null,
63
- ]);
64
- const { points } = await qdrant.scrollPoints(COLLECTION, filter, options.limit ?? defaultLimit);
65
-
66
- return points.map((p) => ({
67
- id: p.id,
68
- from: p.payload.from as string,
69
- relationType: p.payload.relationType as string,
70
- to: p.payload.to as string,
71
- metadata: p.payload.metadata as Record<string, unknown> | undefined,
72
- }));
73
- }
74
-
75
- export async function deleteRelations(options: { from?: string; to?: string; relationType?: string }): Promise<void> {
76
- const filter = buildFilter([
77
- options.from ? { key: "from", value: options.from } : null,
78
- options.to ? { key: "to", value: options.to } : null,
79
- options.relationType ? { key: "relationType", value: options.relationType } : null,
80
- ]);
81
- if (!filter) return;
82
-
83
- await qdrant.deleteByFilter(COLLECTION, filter);
84
- }
85
-
86
- export async function getRelationStats(): Promise<{
87
- count: number;
88
- vectorsCount: number;
89
- indexedVectorsCount: number;
90
- }> {
91
- const info = await qdrant.getCollectionInfo(COLLECTION);
92
- if (!info) return { count: 0, vectorsCount: 0, indexedVectorsCount: 0 };
93
- return {
94
- count: info.pointsCount,
95
- vectorsCount: info.vectorsCount,
96
- indexedVectorsCount: info.indexedVectorsCount,
97
- };
98
- }
99
-
100
- export async function listRelations(
101
- relationType?: string,
102
- limit: number = 100,
103
- offset?: string,
104
- ): Promise<{ relations: Relation[]; offset: string | null }> {
105
- const filter = buildFilter([
106
- relationType ? { key: "relationType", value: relationType } : null,
107
- ]);
108
-
109
- const { points, nextPageOffset } = await qdrant.scrollPoints(
110
- COLLECTION,
111
- filter,
112
- limit,
113
- offset,
114
- );
115
-
116
- return {
117
- relations: points.map((p) => ({
118
- id: p.id,
119
- from: p.payload.from as string,
120
- relationType: p.payload.relationType as string,
121
- to: p.payload.to as string,
122
- metadata: p.payload.metadata as Record<string, unknown> | undefined,
123
- })),
124
- offset: nextPageOffset,
125
- };
126
- }
127
-
128
- export async function initRelationCollection(): Promise<void> {
129
- await qdrant.ensureCollection(COLLECTION, config.vector.dim, [
130
- "from",
131
- "to",
132
- "relationType",
133
- ]);
134
- }
135
-
136
- export const relationRepository = {
137
- create: createRelation,
138
- search: searchRelations,
139
- delete: deleteRelations,
140
- init: initRelationCollection,
141
- stats: getRelationStats,
142
- list: listRelations,
143
- };