new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

AI SDK · Cookbook · all subjects

rag/database

4 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

RAG workflow with embeddings table

The embeddings table in the database stores chunks of source material along with their vector representations. The table structure includes: id (unique identifier), resourceId (foreign key to source material), content (plain text chunk), and embedding (vector representation with dimensions: 1536). An HNSW or IVFFlat index on the embedding column improves similarity search performance.

Create embeddings table schema with Drizzle ORM

Example schema definition for storing embeddings in PostgreSQL with pgvector: import { nanoid } from '@/lib/utils'; import { index, pgTable, text, varchar, vector } from 'drizzle-orm/pg-core'; import { resources } from './resources'; export const embeddings = pgTable( 'embeddings', { id: varchar('id', { length: 191 }) .primaryKey() .$defaultFn(() => nanoid()), resourceId: varchar('resource_id', { length: 191 }).references( () => resources.id, { onDelete: 'cascade' }, ), content: text('content').notNull(), embedding: vector('embedding', { dimensions: 1536 }).notNull(), }, table => ({ embeddingIndex: index('embeddingIndex').using( 'hnsw', table.embedding.op('vector_cosine_ops'), ), }), );

RAG in-memory vector database implementation

A simple RAG implementation stores embedded chunks in memory as an array of objects with embedding vectors and original text values. Each chunk of source text is embedded using an embedding model, then stored alongside its embedding vector for later similarity comparisons.

Upstash Search features for knowledge base

Upstash Search provides input enrichment, reranking, semantic search, and full-text search capabilities. It includes a built-in embedding service, eliminating the need for a separate embedding provider. This makes it convenient for building and managing simple knowledge bases.

Give your agent this brain