File size: 961 Bytes
1257299
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
async function testAddDocument() {
  const response = await fetch('http://localhost:3000/api/embeddings', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      content: 'Next.js is a React framework for building web applications.',
      title: 'Next.js Introduction',
      metadata: { category: 'web development' }
    })
  })

  const result = await response.json()
  console.log('Document added:', result)
}

async function testSearch() {
  const response = await fetch('http://localhost:3000/api/search', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      query: 'What is Next.js?',
      match_threshold: 0.5,
      match_count: 3
    })
  })

  const result = await response.json()
  console.log('Search results:', result)
}

// Run tests
testAddDocument()
  .then(() => testSearch())
  .catch(console.error)