Coding
PromptBeginner5 minmarkdown
Markdown Converter
Agent skill for markdown-converter
7
This is a RAG (Retrieval-Augmented Generation) system in TypeScript/Node.js that allows:
Sign in to like and favorite skills
This is a RAG (Retrieval-Augmented Generation) system in TypeScript/Node.js that allows:
src/ ├── index.ts # Main Express server routes/ # REST API endpoints ├── upload.ts # POST /upload - File upload ├── ingest.ts # POST /ingest - Processing and ingestion └── query.ts # POST /query - RAG queries services/ # Service layer ├── dbService.ts # PostgreSQL connection pool ├── embeddingService.ts # OpenAI embedding generation └── chunckService.ts # Text chunking division utils/ └── logger.ts # Logging utilities
dbService.tsSELECT content, embedding <-> $1 AS distancetext-embedding-3-smallgpt-4o-miniimport express from "express"; import { pool } from "../services/dbService"; const router = express.Router(); router.post("/", async (req, res) => { try { const { param1, param2 } = req.body; if (!param1 || !param2) { return res.status(400).json({ error: "Missing required parameters" }); } // Endpoint logic res.status(200).json({ message: "Success" }); } catch (error) { console.error("Error in route:", error); res.status(500).json({ error: "Internal server error" }); } }); export default router;
const results = await pool.query( "SELECT content, embedding <-> $1 AS distance FROM chunks ORDER BY distance ASC LIMIT 5", [vector] );
const embeddingRes = await openai.embeddings.create({ model: "text-embedding-3-small", input: text, }); const vector = embeddingRes?.data[0]?.embedding;
-- Documents documents ( id SERIAL PRIMARY KEY, name VARCHAR NOT NULL ) -- Chunks with embeddings chunks ( id SERIAL PRIMARY KEY, document_id INTEGER REFERENCES documents(id), content TEXT NOT NULL, embedding vector(1536) -- OpenAI embedding size )
<-> operatorOPENAI_API_KEY=your_openai_api_key DATABASE_URL=postgresql://user:password@localhost:5432/dbname PORT=3000
"type": "commonjs" in package.json)uploads/ folder