ваше сообщение коммита
This commit is contained in:
@@ -1,57 +1,89 @@
|
||||
const axios = require('axios');
|
||||
const logger = require('../utils/logger');
|
||||
|
||||
const VECTOR_SEARCH_URL = process.env.VECTOR_SEARCH_URL || 'http://vector-search:8001';
|
||||
|
||||
async function upsert(tableId, rows) {
|
||||
const res = await axios.post(`${VECTOR_SEARCH_URL}/upsert`, {
|
||||
table_id: String(tableId),
|
||||
rows: rows.map(r => ({
|
||||
row_id: String(r.row_id),
|
||||
text: r.text,
|
||||
metadata: r.metadata || {}
|
||||
}))
|
||||
});
|
||||
return res.data;
|
||||
logger.info(`[VectorSearch] upsert: tableId=${tableId}, rows=${rows.length}`);
|
||||
try {
|
||||
const res = await axios.post(`${VECTOR_SEARCH_URL}/upsert`, {
|
||||
table_id: String(tableId),
|
||||
rows: rows.map(r => ({
|
||||
row_id: String(r.row_id),
|
||||
text: r.text,
|
||||
metadata: r.metadata || {}
|
||||
}))
|
||||
});
|
||||
logger.info(`[VectorSearch] upsert result:`, res.data);
|
||||
return res.data;
|
||||
} catch (error) {
|
||||
logger.error(`[VectorSearch] upsert error:`, error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function search(tableId, query, topK = 3) {
|
||||
const res = await axios.post(`${VECTOR_SEARCH_URL}/search`, {
|
||||
table_id: String(tableId),
|
||||
query,
|
||||
top_k: topK
|
||||
});
|
||||
return res.data.results;
|
||||
logger.info(`[VectorSearch] search: tableId=${tableId}, query="${query}", topK=${topK}`);
|
||||
try {
|
||||
const res = await axios.post(`${VECTOR_SEARCH_URL}/search`, {
|
||||
table_id: String(tableId),
|
||||
query,
|
||||
top_k: topK
|
||||
});
|
||||
logger.info(`[VectorSearch] search result:`, res.data.results);
|
||||
return res.data.results;
|
||||
} catch (error) {
|
||||
logger.error(`[VectorSearch] search error:`, error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(tableId, rowIds) {
|
||||
const res = await axios.post(`${VECTOR_SEARCH_URL}/delete`, {
|
||||
table_id: String(tableId),
|
||||
row_ids: rowIds.map(id => String(id))
|
||||
});
|
||||
return res.data;
|
||||
logger.info(`[VectorSearch] remove: tableId=${tableId}, rowIds=${rowIds}`);
|
||||
try {
|
||||
const res = await axios.post(`${VECTOR_SEARCH_URL}/remove`, {
|
||||
table_id: String(tableId),
|
||||
row_ids: rowIds.map(String)
|
||||
});
|
||||
logger.info(`[VectorSearch] remove result:`, res.data);
|
||||
return res.data;
|
||||
} catch (error) {
|
||||
logger.error(`[VectorSearch] remove error:`, error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function rebuild(tableId, rows) {
|
||||
const res = await axios.post(`${VECTOR_SEARCH_URL}/rebuild`, {
|
||||
table_id: String(tableId),
|
||||
rows: rows.map(r => ({
|
||||
row_id: String(r.row_id),
|
||||
text: r.text,
|
||||
metadata: r.metadata || {}
|
||||
}))
|
||||
});
|
||||
return res.data;
|
||||
logger.info(`[VectorSearch] rebuild: tableId=${tableId}, rows=${rows.length}`);
|
||||
try {
|
||||
const res = await axios.post(`${VECTOR_SEARCH_URL}/rebuild`, {
|
||||
table_id: String(tableId),
|
||||
rows: rows.map(r => ({
|
||||
row_id: String(r.row_id),
|
||||
text: r.text,
|
||||
metadata: r.metadata || {}
|
||||
}))
|
||||
});
|
||||
logger.info(`[VectorSearch] rebuild result:`, res.data);
|
||||
return res.data;
|
||||
} catch (error) {
|
||||
logger.error(`[VectorSearch] rebuild error:`, error.message);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async function health() {
|
||||
logger.info(`[VectorSearch] health check`);
|
||||
try {
|
||||
const res = await axios.get(`${VECTOR_SEARCH_URL}/health`, { timeout: 5000 });
|
||||
logger.info(`[VectorSearch] health result:`, res.data);
|
||||
return {
|
||||
status: 'ok',
|
||||
url: VECTOR_SEARCH_URL,
|
||||
response: res.data
|
||||
};
|
||||
} catch (error) {
|
||||
logger.error(`[VectorSearch] health error:`, error.message);
|
||||
return {
|
||||
status: 'error',
|
||||
url: VECTOR_SEARCH_URL,
|
||||
|
||||
Reference in New Issue
Block a user