@@ -20,7 +20,7 @@ async function testVectorDB() {
2020 } ;
2121
2222 try {
23- const addResult = await codebolt . vectordb . addVectorItem ( testItem ) ;
23+ const addResult = await codebolt . vectordb . addVectorItem ( "This is a test document for vector database" ) ;
2424 console . log ( '✅ Vector item addition result:' , addResult ) ;
2525 console . log ( ' - Type:' , addResult ?. type ) ;
2626 console . log ( ' - Success:' , addResult ?. success ) ;
@@ -65,39 +65,9 @@ async function testVectorDB() {
6565 } catch ( error ) {
6666 console . log ( '⚠️ Multiple vector query failed:' , error . message ) ;
6767 }
68+
6869
69- console . log ( '\n5. Testing vector addition with different data types...' ) ;
70- const dataTypes = [
71- {
72- id : 'code-snippet-001' ,
73- content : 'function fibonacci(n) { return n <= 1 ? n : fibonacci(n-1) + fibonacci(n-2); }' ,
74- type : 'code' ,
75- language : 'javascript'
76- } ,
77- {
78- id : 'text-doc-001' ,
79- content : 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.' ,
80- type : 'text' ,
81- language : 'latin'
82- } ,
83- {
84- id : 'json-data-001' ,
85- content : JSON . stringify ( { users : [ { id : 1 , name : 'John' } ] } ) ,
86- type : 'json' ,
87- structure : 'object'
88- }
89- ] ;
90-
91- for ( const item of dataTypes ) {
92- try {
93- const typeResult = await codebolt . vectordb . addVectorItem ( item ) ;
94- console . log ( `✅ ${ item . type } vector addition:` , ! ! typeResult ) ;
95- } catch ( error ) {
96- console . log ( `⚠️ ${ item . type } vector addition failed:` , error . message ) ;
97- }
98- }
99-
100- console . log ( '\n6. Testing vector search with similarity...' ) ;
70+ console . log ( '\n5. Testing vector search with similarity...' ) ;
10171 try {
10272 const similarityQuery = 'fibonacci recursive function' ;
10373 const similarityResult = await codebolt . vectordb . queryVectorItem ( similarityQuery ) ;
@@ -107,88 +77,8 @@ async function testVectorDB() {
10777 console . log ( '⚠️ Similarity search failed:' , error . message ) ;
10878 }
10979
110- console . log ( '\n7. Testing vector database with large content...' ) ;
111- const largeContent = {
112- id : 'large-doc-001' ,
113- content : 'Large document content. ' . repeat ( 1000 ) ,
114- metadata : {
115- size : 'large' ,
116- wordCount : 3000 ,
117- category : 'documentation'
118- }
119- } ;
120-
121- try {
122- const largeResult = await codebolt . vectordb . addVectorItem ( largeContent ) ;
123- console . log ( '✅ Large content vector addition:' , ! ! largeResult ) ;
124- console . log ( ' - Content size:' , largeContent . content . length ) ;
125- } catch ( error ) {
126- console . log ( '⚠️ Large content addition failed:' , error . message ) ;
127- }
128-
129- console . log ( '\n8. Testing vector retrieval with non-existent key...' ) ;
130- try {
131- const nonExistentResult = await codebolt . vectordb . getVector ( 'non-existent-key' ) ;
132- console . log ( '✅ Non-existent key result:' , nonExistentResult ) ;
133- } catch ( error ) {
134- console . log ( '✅ Expected error for non-existent key:' , error . message ) ;
135- }
136-
137- console . log ( '\n9. Testing vector query with empty string...' ) ;
138- try {
139- const emptyQueryResult = await codebolt . vectordb . queryVectorItem ( '' ) ;
140- console . log ( '✅ Empty query result:' , emptyQueryResult ) ;
141- } catch ( error ) {
142- console . log ( '⚠️ Empty query failed:' , error . message ) ;
143- }
144-
145- console . log ( '\n10. Testing vector database performance...' ) ;
146- const startTime = Date . now ( ) ;
147- const performanceItems = Array . from ( { length : 10 } , ( _ , i ) => ( {
148- id : `perf-test-${ i } ` ,
149- content : `Performance test document ${ i } ` ,
150- index : i
151- } ) ) ;
152-
153- let successCount = 0 ;
154- for ( const item of performanceItems ) {
155- try {
156- await codebolt . vectordb . addVectorItem ( item ) ;
157- successCount ++ ;
158- } catch ( error ) {
159- console . log ( `⚠️ Performance test item ${ item . index } failed` ) ;
160- }
161- }
162-
163- const endTime = Date . now ( ) ;
164- console . log ( '✅ Performance test results:' , {
165- totalItems : performanceItems . length ,
166- successfulItems : successCount ,
167- duration : `${ endTime - startTime } ms` ,
168- averageTime : `${ ( endTime - startTime ) / performanceItems . length } ms per item`
169- } ) ;
170-
171- console . log ( '\n11. Testing vector query with special characters...' ) ;
172- try {
173- const specialQuery = 'test@example.com & special-characters_123' ;
174- const specialResult = await codebolt . vectordb . queryVectorItem ( specialQuery ) ;
175- console . log ( '✅ Special characters query result:' , specialResult ) ;
176- } catch ( error ) {
177- console . log ( '⚠️ Special characters query failed:' , error . message ) ;
178- }
179-
180- console . log ( '\n12. Testing vector database with different database paths...' ) ;
181- const dbPaths = [ './test_db' , './vectors' , './embeddings' ] ;
182- const testQueries = [ 'test query 1' , 'test query 2' ] ;
183-
184- for ( const dbPath of dbPaths ) {
185- try {
186- const pathResult = await codebolt . vectordb . queryVectorItems ( testQueries , dbPath ) ;
187- console . log ( `✅ Database path ${ dbPath } :` , ! ! pathResult ) ;
188- } catch ( error ) {
189- console . log ( `⚠️ Database path ${ dbPath } failed:` , error . message ) ;
190- }
191- }
80+
81+
19282
19383 console . log ( '\n🎉 All vector database tests completed successfully!' ) ;
19484
0 commit comments