fix(drizzle-duckdb-wasm): rename
This commit is contained in:
@@ -46,6 +46,13 @@ const toggleDark = useToggle(isDark)
|
||||
>
|
||||
<h1>Memory Decay</h1>
|
||||
</RouterLink>
|
||||
<div bg="neutral-200 dark:neutral-600" h="1lh" w="0.5" />
|
||||
<RouterLink
|
||||
to="/memory-simulator" px-3 py-2 bg="hover:neutral-200 dark:hover:neutral-700"
|
||||
transition="all duration-250 ease-in-out"
|
||||
>
|
||||
<h1>Memory Simulate</h1>
|
||||
</RouterLink>
|
||||
</nav>
|
||||
<RouterView />
|
||||
</div>
|
||||
|
||||
@@ -1,21 +1,13 @@
|
||||
<!-- src/components/MemoryDetails.vue -->
|
||||
<script setup lang="ts">
|
||||
import type { MemoryItem } from '../../types/memory/memory-decay'
|
||||
|
||||
import { computed } from 'vue'
|
||||
|
||||
const props = defineProps({
|
||||
memory: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
longTermMemoryEnabled: {
|
||||
type: Boolean,
|
||||
required: true,
|
||||
},
|
||||
longTermMemoryThreshold: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
})
|
||||
const props = defineProps<{
|
||||
memory: MemoryItem
|
||||
longTermMemoryEnabled: boolean
|
||||
longTermMemoryThreshold: number
|
||||
}>()
|
||||
|
||||
const emit = defineEmits(['retrieve'])
|
||||
|
||||
@@ -59,7 +51,7 @@ const strengthPercentage = computed(() => {
|
||||
// Progress percentage for LTM
|
||||
const ltmPercentage = computed(() => {
|
||||
if (props.memory.retrieval_count >= props.longTermMemoryThreshold) {
|
||||
return Math.round(Number.parseFloat(props.memory.ltm_factor || 0) * 100)
|
||||
return Math.round(Number.parseFloat(String(props.memory.ltm_factor || 0)) * 100)
|
||||
}
|
||||
else {
|
||||
return Math.round((props.memory.retrieval_count / props.longTermMemoryThreshold) * 100)
|
||||
@@ -67,7 +59,7 @@ const ltmPercentage = computed(() => {
|
||||
})
|
||||
|
||||
function simulateRetrieval() {
|
||||
emit('retrieve', props.memory.storyid)
|
||||
emit('retrieve', props.memory.id)
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -75,7 +67,7 @@ function simulateRetrieval() {
|
||||
<div class="flex flex-col justify-between rounded-lg bg-white p-4 shadow dark:bg-neutral-800/50">
|
||||
<div class="flex justify-between">
|
||||
<h3 class="font-bold">
|
||||
{{ memory.storyid }}
|
||||
{{ memory.id }}
|
||||
</h3>
|
||||
<button
|
||||
class="rounded-lg bg-blue-100 px-3 py-1 text-xs font-medium dark:bg-blue-900 hover:bg-blue-200 dark:hover:bg-blue-800" h-fit
|
||||
@@ -119,7 +111,7 @@ function simulateRetrieval() {
|
||||
Creation Date:
|
||||
</div>
|
||||
<div class="font-medium" text-right>
|
||||
{{ new Date(memory.lastupdate).toLocaleDateString() }}
|
||||
{{ new Date(memory.updated_at).toLocaleDateString() }}
|
||||
</div>
|
||||
|
||||
<div class="text-sm text-neutral-500 dark:text-neutral-400" tracking-tight>
|
||||
@@ -182,7 +174,7 @@ function simulateRetrieval() {
|
||||
{{ memory.retrieval_count }}/{{ longTermMemoryThreshold }} retrievals
|
||||
</span>
|
||||
<span v-else class="text-sm text-purple-600 font-medium dark:text-purple-400">
|
||||
{{ Math.round(Number.parseFloat(memory.ltm_factor || 0) * 100) }}% stable
|
||||
{{ Math.round(Number.parseFloat(String(memory.ltm_factor || 0)) * 100) }}% stable
|
||||
</span>
|
||||
<span class="text-xs">Permanent</span>
|
||||
</div>
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import type { MemoryItem } from '../../types/memory/memory-decay'
|
||||
|
||||
import { useDark } from '@vueuse/core'
|
||||
import * as d3 from 'd3'
|
||||
import { onMounted, onUnmounted, ref, watchEffect } from 'vue'
|
||||
|
||||
const props = defineProps<{
|
||||
memoryData: MemoryDataItem[]
|
||||
memoryData: MemoryItem[]
|
||||
selectedStoryId: string
|
||||
decayRate: number
|
||||
maxDaysToShow: number
|
||||
@@ -15,20 +17,6 @@ const props = defineProps<{
|
||||
retrievalDecaySlowdown: number
|
||||
}>()
|
||||
|
||||
interface MemoryDataItem {
|
||||
storyid: string
|
||||
score: number
|
||||
lastupdate: string // ISO timestamp
|
||||
last_retrieved_at: string // ISO timestamp
|
||||
retrieval_count: number
|
||||
lastupdate_str: string
|
||||
last_retrieved_str: string
|
||||
age_in_seconds: number
|
||||
time_since_retrieval: number
|
||||
ltm_factor?: number // Optional since it's only present when longTermMemoryEnabled is true
|
||||
decayed_score: number
|
||||
}
|
||||
|
||||
interface DataPoint {
|
||||
x: number
|
||||
y: number
|
||||
@@ -63,7 +51,7 @@ function renderChart() {
|
||||
d3.select(chartContainer.value).selectAll('*').remove()
|
||||
|
||||
// Find the selected story
|
||||
const story = props.memoryData.find(s => s.storyid === props.selectedStoryId)
|
||||
const story = props.memoryData.find(s => s.id === props.selectedStoryId)
|
||||
if (!story)
|
||||
return
|
||||
|
||||
@@ -194,7 +182,7 @@ function renderChart() {
|
||||
addDataPoints(svg, chartData.dataPoints.withRetrievals, xScale, yScale)
|
||||
|
||||
// Add chart title and legends
|
||||
addTitleAndLegends(svg, story.storyid, retrievals, ltmFactor, width)
|
||||
addTitleAndLegends(svg, story.id, retrievals, ltmFactor, width)
|
||||
|
||||
// Add LTM indicators
|
||||
if (props.longTermMemoryEnabled) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<!-- src/components/MemoryTable.vue -->
|
||||
<script setup lang="ts">
|
||||
interface MemoryDataItem {
|
||||
storyid: string
|
||||
id: string
|
||||
score: number
|
||||
lastupdate: string // ISO timestamp
|
||||
updated_at: string // ISO timestamp
|
||||
last_retrieved_at: string // ISO timestamp
|
||||
retrieval_count: number
|
||||
lastupdate_str: string
|
||||
updated_at_str: string
|
||||
last_retrieved_str: string
|
||||
age_in_seconds: number
|
||||
time_since_retrieval: number
|
||||
@@ -103,16 +103,16 @@ function getMemoryStatus(memory) {
|
||||
</thead>
|
||||
<tbody class="bg-white divide-y divide-neutral-200 dark:bg-neutral-900 dark:divide-neutral-800">
|
||||
<tr
|
||||
v-for="(item, idx) in memories" :key="item.storyid"
|
||||
:class="{ 'bg-blue-50 dark:bg-blue-900/20': item.storyid === selectedId }"
|
||||
v-for="(item, idx) in memories" :key="item.id"
|
||||
:class="{ 'bg-blue-50 dark:bg-blue-900/20': item.id === selectedId }"
|
||||
class="cursor-pointer transition duration-150 hover:bg-neutral-50 dark:hover:bg-neutral-800"
|
||||
@click="selectMemory(item.storyid)"
|
||||
@click="selectMemory(item.id)"
|
||||
>
|
||||
<td class="whitespace-nowrap px-4 py-2 text-sm font-medium">
|
||||
{{ idx + 1 }}
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-4 py-2 text-sm">
|
||||
{{ item.storyid }}
|
||||
{{ item.id }}
|
||||
</td>
|
||||
<td class="whitespace-nowrap px-4 py-2 text-sm">
|
||||
{{ Math.round(item.score) }}
|
||||
@@ -154,7 +154,7 @@ function getMemoryStatus(memory) {
|
||||
<td class="whitespace-nowrap px-4 py-2 text-right">
|
||||
<button
|
||||
class="rounded-lg bg-green-100 px-3 py-1 text-xs font-medium dark:bg-green-900 hover:bg-green-200 dark:hover:bg-green-800"
|
||||
@click="retrieveMemory(item.storyid, $event)"
|
||||
@click="retrieveMemory(item.id, $event)"
|
||||
>
|
||||
Retrieve
|
||||
</button>
|
||||
|
||||
+16
-16
@@ -6,16 +6,16 @@ export async function connectToDatabase() {
|
||||
return drizzle(buildDSN({
|
||||
scheme: 'duckdb-wasm:',
|
||||
bundles: 'import-url',
|
||||
logger: true,
|
||||
logger: false,
|
||||
}), { schema })
|
||||
}
|
||||
|
||||
export async function createSchema(db) {
|
||||
await db.execute(`
|
||||
CREATE TABLE IF NOT EXISTS currentscores (
|
||||
storyid VARCHAR,
|
||||
CREATE TABLE IF NOT EXISTS memories_decay_test_table (
|
||||
id VARCHAR,
|
||||
score DOUBLE,
|
||||
lastupdate TIMESTAMP,
|
||||
updated_at TIMESTAMP,
|
||||
last_retrieved_at TIMESTAMP,
|
||||
retrieval_count INTEGER DEFAULT 0
|
||||
)
|
||||
@@ -36,9 +36,9 @@ export async function loadSampleData(db) {
|
||||
const score = Math.floor(Math.random() * 900) + 100
|
||||
|
||||
sampleData.push({
|
||||
storyid: `story-${i}`,
|
||||
id: `story-${i}`,
|
||||
score,
|
||||
lastupdate: lastUpdate.toISOString(),
|
||||
updated_at: lastUpdate.toISOString(),
|
||||
last_retrieved_at: lastRetrievedAt.toISOString(),
|
||||
retrieval_count: retrievalCount,
|
||||
})
|
||||
@@ -46,8 +46,8 @@ export async function loadSampleData(db) {
|
||||
|
||||
for (const item of sampleData) {
|
||||
await db.execute(`
|
||||
INSERT INTO currentscores (storyid, score, lastupdate, last_retrieved_at, retrieval_count)
|
||||
VALUES ('${item.storyid}', ${item.score}, '${item.lastupdate}', '${item.last_retrieved_at}', ${item.retrieval_count})
|
||||
INSERT INTO memories_decay_test_table (id, score, updated_at, last_retrieved_at, retrieval_count)
|
||||
VALUES ('${item.id}', ${item.score}, '${item.updated_at}', '${item.last_retrieved_at}', ${item.retrieval_count})
|
||||
`)
|
||||
}
|
||||
}
|
||||
@@ -80,23 +80,23 @@ export async function generateDecayQuery(db, {
|
||||
|
||||
const query = `
|
||||
SELECT
|
||||
storyid,
|
||||
id,
|
||||
score,
|
||||
lastupdate,
|
||||
updated_at,
|
||||
last_retrieved_at,
|
||||
retrieval_count,
|
||||
CAST(lastupdate AS VARCHAR) as lastupdate_str,
|
||||
CAST(updated_at AS VARCHAR) as updated_at_str,
|
||||
CAST(last_retrieved_at AS VARCHAR) as last_retrieved_str,
|
||||
(EXTRACT(EPOCH FROM (${simulatedTimestamp} - lastupdate))) as age_in_seconds,
|
||||
(EXTRACT(EPOCH FROM (${simulatedTimestamp} - updated_at))) as age_in_seconds,
|
||||
(EXTRACT(EPOCH FROM (${simulatedTimestamp} - last_retrieved_at))) as time_since_retrieval,
|
||||
${ltmFactorClause}
|
||||
score *
|
||||
exp(-${decayRate} * (EXTRACT(EPOCH FROM (${simulatedTimestamp} - lastupdate)))/(${timeUnitInSeconds}) ${ltmDecayModifier}) *
|
||||
exp(-${decayRate} * (EXTRACT(EPOCH FROM (${simulatedTimestamp} - updated_at)))/(${timeUnitInSeconds}) ${ltmDecayModifier}) *
|
||||
(1 + (retrieval_count * ${retrievalBoost} *
|
||||
exp(-${decayRate * retrievalDecaySlowdown} *
|
||||
(EXTRACT(EPOCH FROM (${simulatedTimestamp} - last_retrieved_at)))/(${timeUnitInSeconds}))))
|
||||
as decayed_score
|
||||
FROM currentscores
|
||||
FROM memories_decay_test_table
|
||||
ORDER BY decayed_score DESC
|
||||
`
|
||||
|
||||
@@ -107,9 +107,9 @@ export async function simulateRetrieval(db, storyId, simulatedTime) {
|
||||
const simulatedTimestamp = simulatedTime.toISOString()
|
||||
|
||||
await db.execute(`
|
||||
UPDATE currentscores
|
||||
UPDATE memories_decay_test_table
|
||||
SET last_retrieved_at = '${simulatedTimestamp}',
|
||||
retrieval_count = retrieval_count + 1
|
||||
WHERE storyid = '${storyId}'
|
||||
WHERE id = '${storyId}'
|
||||
`)
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
<!-- src/MemoryDecaySimulator.vue -->
|
||||
<script setup lang="ts">
|
||||
import type { MemoryItem } from '../types/memory/memory-decay'
|
||||
|
||||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
||||
|
||||
import MemoryModelSettings from '../components/Memory/DecayModelSettings.vue'
|
||||
@@ -7,29 +8,21 @@ import TimeControls from '../components/Memory/DecayTimeSettings.vue'
|
||||
import MemoryDetails from '../components/Memory/RecordDetail.vue'
|
||||
import MemoryChart from '../components/Memory/VisualizeChart.vue'
|
||||
import MemoryTable from '../components/Memory/VisualizeTable.vue'
|
||||
import { connectToDatabase, createSchema, generateDecayQuery, loadSampleData, simulateRetrieval } from '../composables/memory/db'
|
||||
|
||||
interface MemoryDataItem {
|
||||
storyid: string
|
||||
score: number
|
||||
lastupdate: string // ISO timestamp
|
||||
last_retrieved_at: string // ISO timestamp
|
||||
retrieval_count: number
|
||||
lastupdate_str: string
|
||||
last_retrieved_str: string
|
||||
age_in_seconds: number
|
||||
time_since_retrieval: number
|
||||
ltm_factor?: number // Optional since it's only present when longTermMemoryEnabled is true
|
||||
decayed_score: number
|
||||
}
|
||||
import {
|
||||
connectToDatabase,
|
||||
createSchema,
|
||||
generateDecayQuery,
|
||||
loadSampleData,
|
||||
simulateRetrieval,
|
||||
} from '../composables/memory/memory-decay-db'
|
||||
|
||||
// Database references
|
||||
const db = ref(null)
|
||||
const isMigrated = ref(false)
|
||||
|
||||
// Data and query results
|
||||
const rawData = ref<MemoryDataItem[]>([])
|
||||
const decayedResults = ref<MemoryDataItem[]>([])
|
||||
const rawData = ref<MemoryItem[]>([])
|
||||
const decayedResults = ref<MemoryItem[]>([])
|
||||
|
||||
// Parameters for decay function
|
||||
const decayRate = ref(0.0990)
|
||||
@@ -58,7 +51,7 @@ const showInfoPanel = ref(false)
|
||||
const selectedMemory = computed(() => {
|
||||
if (!selectedStoryId.value || !decayedResults.value.length)
|
||||
return null
|
||||
return decayedResults.value.find(s => s.storyid === selectedStoryId.value)
|
||||
return decayedResults.value.find(s => s.id === selectedStoryId.value)
|
||||
})
|
||||
|
||||
// Time unit in seconds
|
||||
@@ -91,10 +84,10 @@ async function initialize() {
|
||||
// Load data from the database
|
||||
async function loadData() {
|
||||
rawData.value = await db.value?.execute(`
|
||||
SELECT storyid, score, lastupdate, last_retrieved_at, retrieval_count,
|
||||
CAST(lastupdate AS VARCHAR) as lastupdate_str,
|
||||
CAST(last_retrieved_at AS VARCHAR) as last_retrieved_str
|
||||
FROM currentscores
|
||||
SELECT id, score, updated_at, last_retrieved_at, retrieval_count,
|
||||
CAST(updated_at AS VARCHAR) as updated_at_str,
|
||||
CAST(last_retrieved_at AS VARCHAR) as last_retrieved_str
|
||||
FROM memories_decay_test_table
|
||||
ORDER BY score DESC
|
||||
`) || []
|
||||
await runDecayQuery()
|
||||
@@ -126,7 +119,7 @@ async function runDecayQuery() {
|
||||
|
||||
// Initialize selectedStoryId if not set or update if selection changed
|
||||
if (!selectedStoryId.value && decayedResults.value.length) {
|
||||
selectedStoryId.value = decayedResults.value[0].storyid
|
||||
selectedStoryId.value = decayedResults.value[0].id
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<h1>Memory Simulator</h1>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,13 @@
|
||||
export interface MemoryItem {
|
||||
id: string
|
||||
score: number
|
||||
updated_at: string // ISO timestamp
|
||||
last_retrieved_at: string // ISO timestamp
|
||||
retrieval_count: number
|
||||
updated_at_str: string
|
||||
last_retrieved_str: string
|
||||
age_in_seconds: number
|
||||
time_since_retrieval: number
|
||||
ltm_factor?: number // Optional since it's only present when longTermMemoryEnabled is true
|
||||
decayed_score: number
|
||||
}
|
||||
Reference in New Issue
Block a user