sync: ingestion improvements from private repo
- Fixed dimension auto-assignment (locked dimensions now properly assigned) - Added description field as grounding context for AI - Updated embedding format: Title → Description → Content → Dimensions - Description-weighted search (5x boost) - Bug fixes: extraction tool dimension display, DimensionSearchModal closing - Removed quickLink tool (use Quick Link workflow instead) - Added regenerate-description API endpoint
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { nodeService } from '@/services/database';
|
||||
import { generateDescription } from '@/services/database/descriptionService';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
export async function POST(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params;
|
||||
const nodeId = parseInt(id, 10);
|
||||
|
||||
if (isNaN(nodeId)) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Invalid node ID'
|
||||
}, { status: 400 });
|
||||
}
|
||||
|
||||
const node = await nodeService.getNodeById(nodeId);
|
||||
|
||||
if (!node) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Node not found'
|
||||
}, { status: 404 });
|
||||
}
|
||||
|
||||
// Generate new description using the description service
|
||||
const newDescription = await generateDescription({
|
||||
title: node.title,
|
||||
content: node.content || undefined,
|
||||
metadata: node.metadata as { source?: string; channel_name?: string; author?: string; site_name?: string } | undefined,
|
||||
type: (node.metadata as { type?: string } | null)?.type
|
||||
});
|
||||
|
||||
// Update the node with the new description
|
||||
const updatedNode = await nodeService.updateNode(nodeId, {
|
||||
description: newDescription
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
node: updatedNode,
|
||||
description: newDescription,
|
||||
message: 'Description regenerated successfully'
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error regenerating description:', error);
|
||||
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : 'Failed to regenerate description'
|
||||
}, { status: 500 });
|
||||
}
|
||||
}
|
||||
+20
-3
@@ -4,6 +4,7 @@ import { Node, NodeFilters } from '@/types/database';
|
||||
import { autoEmbedQueue } from '@/services/embedding/autoEmbedQueue';
|
||||
import { hasSufficientContent } from '@/services/embedding/constants';
|
||||
import { DimensionService } from '@/services/database/dimensionService';
|
||||
import { generateDescription } from '@/services/database/descriptionService';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
|
||||
@@ -60,17 +61,32 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
const rawContent = typeof body.content === 'string' ? body.content : null;
|
||||
|
||||
// Generate description BEFORE dimension assignment (used as primary context for matching)
|
||||
let nodeDescription: string | undefined;
|
||||
try {
|
||||
nodeDescription = await generateDescription({
|
||||
title: body.title,
|
||||
content: rawContent || undefined,
|
||||
metadata: body.metadata,
|
||||
type: body.type
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error generating description:', error);
|
||||
// Continue without description - dimension assignment will use content as fallback
|
||||
}
|
||||
|
||||
const providedDimensions = Array.isArray(body.dimensions) ? body.dimensions : [];
|
||||
const trimmedProvidedDimensions = providedDimensions
|
||||
.map((dim: unknown) => typeof dim === 'string' ? dim.trim() : '')
|
||||
.filter(Boolean)
|
||||
.slice(0, 5);
|
||||
.slice(0, 8);
|
||||
|
||||
// Auto-assign locked dimensions + keyword dimensions for all new nodes
|
||||
const { locked, keywords } = await DimensionService.assignDimensions({
|
||||
title: body.title,
|
||||
content: rawContent || undefined,
|
||||
link: body.link
|
||||
link: body.link,
|
||||
description: nodeDescription
|
||||
});
|
||||
|
||||
// Ensure keyword dimensions exist in the database (create if new)
|
||||
@@ -80,7 +96,7 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
// Combine provided, locked, and keyword dimensions, remove duplicates
|
||||
const finalDimensions = [...new Set([...trimmedProvidedDimensions, ...locked, ...keywords])]
|
||||
.slice(0, 5); // Ensure we don't exceed 5 total dimensions
|
||||
.slice(0, 8); // max 8 total
|
||||
const rawChunk = typeof body.chunk === 'string' ? body.chunk : null;
|
||||
let chunkToStore = rawChunk;
|
||||
let chunkStatus: Node['chunk_status'];
|
||||
@@ -94,6 +110,7 @@ export async function POST(request: NextRequest) {
|
||||
|
||||
const node = await nodeService.createNode({
|
||||
title: body.title,
|
||||
description: nodeDescription,
|
||||
content: rawContent ?? undefined,
|
||||
link: body.link,
|
||||
dimensions: finalDimensions,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { enqueueQuickAdd, QuickAddMode } from '@/services/agents/quickAdd';
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { input, mode } = body as { input?: unknown; mode?: unknown };
|
||||
const { input, mode, description } = body as { input?: unknown; mode?: unknown; description?: unknown };
|
||||
|
||||
if (typeof input !== 'string' || input.trim().length === 0) {
|
||||
return NextResponse.json(
|
||||
@@ -16,9 +16,13 @@ export async function POST(request: NextRequest) {
|
||||
const normalizedMode: QuickAddMode | undefined =
|
||||
mode === 'link' || mode === 'note' || mode === 'chat' ? mode : undefined;
|
||||
|
||||
const normalizedDescription: string | undefined =
|
||||
typeof description === 'string' && description.trim() ? description.trim() : undefined;
|
||||
|
||||
const delegation = await enqueueQuickAdd({
|
||||
rawInput: input.trim(),
|
||||
mode: normalizedMode,
|
||||
description: normalizedDescription,
|
||||
});
|
||||
|
||||
return NextResponse.json({ success: true, delegation });
|
||||
|
||||
Reference in New Issue
Block a user