-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-vectorstore-persistence.html
More file actions
209 lines (193 loc) · 8.56 KB
/
test-vectorstore-persistence.html
File metadata and controls
209 lines (193 loc) · 8.56 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>VectorStore Persistence Test</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
line-height: 1.6;
}
.test-section {
margin: 20px 0;
padding: 15px;
border: 1px solid #ddd;
border-radius: 5px;
background-color: #f9f9f9;
}
button {
background-color: #007bff;
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
margin: 5px;
}
button:hover {
background-color: #0056b3;
}
.result {
margin-top: 10px;
padding: 10px;
background-color: #e9ecef;
border-radius: 4px;
white-space: pre-wrap;
}
.success {
background-color: #d4edda;
color: #155724;
}
.error {
background-color: #f8d7da;
color: #721c24;
}
</style>
</head>
<body>
<h1>VectorStore Persistence Test</h1>
<p>This page tests the VectorStoreSelector persistence functionality.</p>
<div class="test-section">
<h2>Test 1: Add Custom VectorStore</h2>
<p>This simulates what happens when a user creates a new vectorset like "newmem".</p>
<button onclick="addCustomVectorStore('newmem')">Add "newmem" to custom vectorsets</button>
<button onclick="addCustomVectorStore('test-vectorset')">Add "test-vectorset" to custom vectorsets</button>
<button onclick="addCustomVectorStore('my-project-memory')">Add "my-project-memory" to custom vectorsets</button>
<div id="add-result" class="result"></div>
</div>
<div class="test-section">
<h2>Test 2: View Current Custom VectorStores</h2>
<button onclick="showCustomVectorStores()">Show Custom VectorStores</button>
<div id="show-result" class="result"></div>
</div>
<div class="test-section">
<h2>Test 3: Clear All Custom VectorStores</h2>
<button onclick="clearCustomVectorStores()">Clear All Custom VectorStores</button>
<div id="clear-result" class="result"></div>
</div>
<div class="test-section">
<h2>Test 4: Check Predefined VectorStores</h2>
<p>These should NOT be added to custom list (they're already predefined):</p>
<button onclick="addCustomVectorStore('memories')">Try to add "memories" (should be ignored)</button>
<button onclick="addCustomVectorStore('travel_agent_memory')">Try to add "travel_agent_memory" (should be ignored)</button>
<div id="predefined-result" class="result"></div>
</div>
<div class="test-section">
<h2>Current localStorage Contents</h2>
<button onclick="showLocalStorage()">Show All localStorage</button>
<div id="localstorage-result" class="result"></div>
</div>
<script>
// Constants matching the VectorStoreSelector component
const CUSTOM_VECTORSTORES_STORAGE_KEY = 'custom-vectorset-names';
const PREDEFINED_VECTORSTORES = [
'memories',
'travel_agent_memory',
'retail_agent_memory',
'investment_agent_memory'
];
// Function to add a custom vectorset (simulating the component logic)
function addCustomVectorStore(name) {
const trimmedName = name.trim();
if (!trimmedName) {
document.getElementById('add-result').textContent = 'Error: Empty name provided';
document.getElementById('add-result').className = 'result error';
return;
}
// Check if it's already in predefined list
const isPredefined = PREDEFINED_VECTORSTORES.includes(trimmedName);
if (isPredefined) {
document.getElementById('add-result').textContent = `"${trimmedName}" is predefined - not added to custom list`;
document.getElementById('add-result').className = 'result';
document.getElementById('predefined-result').textContent = `"${trimmedName}" is predefined - correctly ignored`;
document.getElementById('predefined-result').className = 'result success';
return;
}
// Get current custom vectorsets
let customVectorStores = [];
try {
const saved = localStorage.getItem(CUSTOM_VECTORSTORES_STORAGE_KEY);
if (saved) {
const parsed = JSON.parse(saved);
if (Array.isArray(parsed)) {
customVectorStores = parsed;
}
}
} catch (error) {
console.error('Failed to load custom vectorset names:', error);
}
// Check if already exists
if (customVectorStores.includes(trimmedName)) {
document.getElementById('add-result').textContent = `"${trimmedName}" already exists in custom list`;
document.getElementById('add-result').className = 'result';
return;
}
// Add to list
customVectorStores.push(trimmedName);
// Save to localStorage
try {
localStorage.setItem(CUSTOM_VECTORSTORES_STORAGE_KEY, JSON.stringify(customVectorStores));
document.getElementById('add-result').textContent = `Successfully added "${trimmedName}" to custom vectorsets`;
document.getElementById('add-result').className = 'result success';
} catch (error) {
document.getElementById('add-result').textContent = `Failed to save: ${error.message}`;
document.getElementById('add-result').className = 'result error';
}
}
function showCustomVectorStores() {
try {
const saved = localStorage.getItem(CUSTOM_VECTORSTORES_STORAGE_KEY);
if (saved) {
const parsed = JSON.parse(saved);
if (Array.isArray(parsed)) {
document.getElementById('show-result').textContent = `Custom VectorStores: ${JSON.stringify(parsed, null, 2)}`;
document.getElementById('show-result').className = 'result success';
} else {
document.getElementById('show-result').textContent = 'Invalid data format in localStorage';
document.getElementById('show-result').className = 'result error';
}
} else {
document.getElementById('show-result').textContent = 'No custom vectorsets found';
document.getElementById('show-result').className = 'result';
}
} catch (error) {
document.getElementById('show-result').textContent = `Error: ${error.message}`;
document.getElementById('show-result').className = 'result error';
}
}
function clearCustomVectorStores() {
try {
localStorage.removeItem(CUSTOM_VECTORSTORES_STORAGE_KEY);
document.getElementById('clear-result').textContent = 'Successfully cleared all custom vectorsets';
document.getElementById('clear-result').className = 'result success';
} catch (error) {
document.getElementById('clear-result').textContent = `Error: ${error.message}`;
document.getElementById('clear-result').className = 'result error';
}
}
function showLocalStorage() {
const result = {};
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
const value = localStorage.getItem(key);
try {
result[key] = JSON.parse(value);
} catch {
result[key] = value;
}
}
document.getElementById('localstorage-result').textContent = JSON.stringify(result, null, 2);
document.getElementById('localstorage-result').className = 'result';
}
// Auto-refresh display on page load
window.addEventListener('load', () => {
showCustomVectorStores();
showLocalStorage();
});
</script>
</body>
</html>