Spaces:
Sleeping
Sleeping
File size: 1,498 Bytes
90cbf22 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import { v } from 'convex/values';
import { playerId, conversationId } from '../aiTown/ids';
import { defineTable } from 'convex/server';
import { LLM_CONFIG } from '../util/llm';
export const memoryFields = {
playerId,
description: v.string(),
embeddingId: v.id('memoryEmbeddings'),
importance: v.number(),
lastAccess: v.number(),
data: v.union(
// Setting up dynamics between players
v.object({
type: v.literal('relationship'),
// The player this memory is about, from the perspective of the player
// whose memory this is.
playerId,
}),
v.object({
type: v.literal('conversation'),
conversationId,
// The other player(s) in the conversation.
playerIds: v.array(playerId),
}),
v.object({
type: v.literal('reflection'),
relatedMemoryIds: v.array(v.id('memories')),
}),
),
};
export const memoryTables = {
memories: defineTable(memoryFields)
.index('embeddingId', ['embeddingId'])
.index('playerId_type', ['playerId', 'data.type'])
.index('playerId', ['playerId']),
memoryEmbeddings: defineTable({
playerId,
embedding: v.array(v.float64()),
}).vectorIndex('embedding', {
vectorField: 'embedding',
filterFields: ['playerId'],
dimensions: LLM_CONFIG.embeddingDimension,
}),
};
export const agentTables = {
...memoryTables,
embeddingsCache: defineTable({
textHash: v.bytes(),
embedding: v.array(v.float64()),
}).index('text', ['textHash']),
};
|