fix: port search and dimension safety guardrails
- enforce canonical dimensions across app and MCP surfaces - prioritize title-first node search in UI and query tools - add regression tests for ranking and dimension validation
This commit is contained in:
@@ -26,20 +26,13 @@ async function getPopularDimensionsSQLite() {
|
||||
SELECT nd.dimension, COUNT(*) AS count
|
||||
FROM node_dimensions nd
|
||||
GROUP BY nd.dimension
|
||||
),
|
||||
all_dimensions AS (
|
||||
SELECT DISTINCT dimension AS name FROM node_dimensions
|
||||
UNION
|
||||
SELECT name FROM dimensions
|
||||
)
|
||||
SELECT ad.name AS dimension,
|
||||
SELECT d.name AS dimension,
|
||||
COALESCE(dc.count, 0) AS count,
|
||||
dim.description
|
||||
FROM all_dimensions ad
|
||||
LEFT JOIN dimension_counts dc ON dc.dimension = ad.name
|
||||
LEFT JOIN dimensions dim ON dim.name = ad.name
|
||||
WHERE ad.name IS NOT NULL
|
||||
ORDER BY LOWER(ad.name) ASC
|
||||
d.description
|
||||
FROM dimensions d
|
||||
LEFT JOIN dimension_counts dc ON dc.dimension = d.name
|
||||
ORDER BY LOWER(d.name) ASC
|
||||
`);
|
||||
|
||||
return NextResponse.json({
|
||||
|
||||
@@ -3,6 +3,7 @@ import { nodeService } from '@/services/database';
|
||||
import { autoEmbedQueue } from '@/services/embedding/autoEmbedQueue';
|
||||
import { hasSufficientContent } from '@/services/embedding/constants';
|
||||
import { normalizeDimensions, validateExplicitDescription } from '@/services/database/quality';
|
||||
import { formatUnknownDimensionsError, getUnknownDimensions } from '@/services/database/dimensionValidation';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
@@ -83,6 +84,13 @@ export async function PUT(
|
||||
|
||||
if (Array.isArray(body.dimensions)) {
|
||||
updates.dimensions = normalizeDimensions(body.dimensions, 5);
|
||||
const unknownDimensions = getUnknownDimensions(updates.dimensions as string[]);
|
||||
if (unknownDimensions.length > 0) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: formatUnknownDimensionsError(unknownDimensions)
|
||||
}, { status: 400 });
|
||||
}
|
||||
}
|
||||
|
||||
delete updates.notes;
|
||||
|
||||
@@ -5,6 +5,7 @@ import { autoEmbedQueue } from '@/services/embedding/autoEmbedQueue';
|
||||
import { generateDescription } from '@/services/database/descriptionService';
|
||||
import { scheduleAutoEdgeCreation } from '@/services/agents/autoEdge';
|
||||
import { normalizeDimensions, validateExplicitDescription } from '@/services/database/quality';
|
||||
import { formatUnknownDimensionsError, getUnknownDimensions } from '@/services/database/dimensionValidation';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
@@ -97,6 +98,13 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
// Process provided dimensions first (needed for description generation)
|
||||
const trimmedProvidedDimensions = normalizeDimensions(body.dimensions, 5);
|
||||
const unknownDimensions = getUnknownDimensions(trimmedProvidedDimensions);
|
||||
if (unknownDimensions.length > 0) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: formatUnknownDimensionsError(unknownDimensions)
|
||||
}, { status: 400 });
|
||||
}
|
||||
|
||||
// Use provided description if present, otherwise auto-generate
|
||||
const isUserSuppliedDescription = typeof body.description === 'string' && body.description.trim().length > 0;
|
||||
|
||||
Reference in New Issue
Block a user