Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions app/api/ask/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { NextRequest, NextResponse } from "next/server";
import { RAGPipeline } from "@/lib/rag/pipeline";

export async function POST(req: NextRequest) {
const body = await req.json();
const question = (body.question || body.query || "").toString().trim();
if (!question) {
return NextResponse.json({ error: "Question required" }, { status: 400 });
}

const pipeline = await RAGPipeline.getInstance();
const { answer, context, results } = await pipeline.ask(question, 5);
return NextResponse.json({
answer,
context,
sources: results.map((r) => ({
id: r.chunkId,
docId: r.docId,
title: r.title,
text: r.text,
score: r.score,
})),
});
}
14 changes: 14 additions & 0 deletions app/api/documents/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { NextResponse } from "next/server";

import { RAGPipeline } from "@/lib/rag/pipeline";

export async function GET(_: Request, { params }: { params: { id: string } }) {
const pipeline = await RAGPipeline.getInstance();
const document = pipeline.getDocument(params.id);

if (!document) {
return NextResponse.json({ error: "Not found" }, { status: 404 });
}

return NextResponse.json(document);
}
10 changes: 10 additions & 0 deletions app/api/documents/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NextResponse } from "next/server";

import { RAGPipeline } from "@/lib/rag/pipeline";

export async function GET() {
const pipeline = await RAGPipeline.getInstance();
return NextResponse.json({
documents: pipeline.listDocuments(),
});
}
21 changes: 21 additions & 0 deletions app/api/search/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { NextRequest, NextResponse } from "next/server";
import { RAGPipeline } from "@/lib/rag/pipeline";

export async function POST(req: NextRequest) {
const { query } = await req.json();
if (!query) return NextResponse.json({ error: "Query required" }, { status: 400 });

const pipeline = await RAGPipeline.getInstance();
const results = await pipeline.search(query, 5);

return NextResponse.json({
results: results.map((r) => ({
id: r.chunkId,
docId: r.docId,
title: r.title,
text: r.text,
snippet: r.text.slice(0, 220),
score: r.score,
})),
});
}
Loading