colpali-backend-api / hono-proxy /src /routes /query-suggestions-vespa.ts
vk98's picture
Initial backend deployment - Hono proxy + ColPali embedding API
5dfbe50
import { Hono } from 'hono';
import { cache } from '../services/cache';
const querySuggestionsApp = new Hono();
// Static suggestions for now (can be replaced with Vespa query later)
const staticSuggestions = [
'linqto bankruptcy',
'linqto filing date',
'linqto creditors',
'linqto assets',
'linqto liabilities',
'linqto chapter 11',
'linqto docket',
'linqto plan',
'linqto disclosure statement',
'linqto claims',
];
// Query suggestions endpoint
querySuggestionsApp.get('/', async (c) => {
try {
const query = c.req.query('query');
if (!query) {
return c.json({ suggestions: [] });
}
// Check cache
const cacheKey = `suggestions:${query}`;
const cachedSuggestions = cache.get(cacheKey);
if (cachedSuggestions) {
c.header('X-Cache', 'HIT');
return c.json(cachedSuggestions);
}
// Filter static suggestions based on query
const lowerQuery = query.toLowerCase();
const filteredSuggestions = staticSuggestions
.filter(s => s.toLowerCase().includes(lowerQuery))
.slice(0, 5);
const result = { suggestions: filteredSuggestions };
// Cache for 5 minutes
cache.set(cacheKey, result, 300);
c.header('X-Cache', 'MISS');
return c.json(result);
} catch (error) {
console.error('Suggestions error:', error);
return c.json({
error: 'Failed to fetch suggestions',
suggestions: []
}, 500);
}
});
export { querySuggestionsApp };