Building a Conversational Interface for MDX Files with Bun and pgvector
Prerequisites
Setting Up PostgreSQL and pgvector
- Install PostgreSQL:
paru postgresql
- Enable the pgvector Extension:
CREATE EXTENSION vector;
- Create the documents Table:
CREATE TABLE documents (
id SERIAL PRIMARY KEY,
filename TEXT NOT NULL,
chunk_index INTEGER NOT NULL,
content TEXT NOT NULL,
embedding VECTOR(1536) NOT NULL
);
CREATE INDEX ON documents USING HNSW (embedding vector_l2_ops);
Data Preprocessing with Bun
This stage involves reading your MDX files, segmenting their content into manageable chunks, and generating vector embeddings for each chunk.