Skip to content

Commit 7fda9d6

Browse files
committedOct 15, 2024
feat: add endpoint to add memory point
1 parent ac7bca2 commit 7fda9d6

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
 

‎src/routes/memory.ts

+48
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,54 @@ export const memoryRoutes = new Elysia({
330330
404: 'error',
331331
500: 'error',
332332
},
333+
}).post('/collections/:collectionId/point', async ({ params, body, log, HttpError }) => {
334+
const { collectionId } = params, { content, payload, vector } = body
335+
try {
336+
const point = await cat.vectorMemory.collections[collectionId]!.addPoint(content, vector, payload)
337+
if (!point) throw new Error('Error adding point.')
338+
return {
339+
id: point.id.toString(),
340+
}
341+
}
342+
catch (error) {
343+
log.error(error)
344+
throw HttpError.InternalServer('Unable to add point in memory.')
345+
}
346+
}, {
347+
detail: {
348+
description: 'Add a point in memory.',
349+
summary: 'Add memory point',
350+
},
351+
body: t.Object({
352+
content: t.String({ title: 'Content', description: 'Content of the point' }),
353+
vector: t.Array(t.Number(), { title: 'Vector', description: 'Vector of the point' }),
354+
payload: t.Record(t.String(), t.Any(), { title: 'Payload', description: 'Metadata of the point' }),
355+
}, {
356+
title: 'Memory Point',
357+
description: 'Point to add in memory',
358+
examples: [{
359+
content: 'Hello, John!',
360+
vector: [0.1, 0.2, 0.3],
361+
payload: {
362+
source: 'user',
363+
},
364+
}],
365+
}),
366+
params: t.Object({
367+
collectionId: t.String({ title: 'Collection ID', description: 'ID of the collection to add the point to' }),
368+
}),
369+
response: {
370+
200: t.Object({
371+
id: t.String(),
372+
}, {
373+
title: 'Memory Point',
374+
description: 'Point added in memory',
375+
examples: [{
376+
id: '1da746f8-a832-4a45-a120-4549e17a1df7',
377+
}],
378+
}),
379+
500: 'error',
380+
},
333381
}).get('/history', ({ stray }) => {
334382
return {
335383
history: stray.getHistory(),

0 commit comments

Comments
 (0)
Please sign in to comment.