mirror of
https://github.com/waynesutton/markdown-site.git
synced 2026-01-12 04:09:14 +00:00
Add vector-based semantic search to complement keyword search. Users can toggle between "Keyword" and "Semantic" modes in the search modal (Cmd+K, then Tab to switch). Semantic search: - Uses OpenAI text-embedding-ada-002 (1536 dimensions) - Finds content by meaning, not exact words - Shows similarity scores as percentages - ~300ms latency, ~$0.0001/query - Graceful fallback if OPENAI_API_KEY not set New files: - convex/embeddings.ts - Embedding generation actions - convex/embeddingsQueries.ts - Queries/mutations for embeddings - convex/semanticSearch.ts - Vector search action - convex/semanticSearchQueries.ts - Result hydration queries - content/pages/docs-search.md - Keyword search docs - content/pages/docs-semantic-search.md - Semantic search docs Changes: - convex/schema.ts: Add embedding field and by_embedding vectorIndex - SearchModal.tsx: Add mode toggle (TextAa/Brain icons) - sync-posts.ts: Generate embeddings after content sync - global.css: Search mode toggle styles Documentation updated: - changelog.md, TASK.md, files.md, about.md, home.md Configuration: npx convex env set OPENAI_API_KEY sk-your-key Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> Status: Ready to commit. All semantic search files are staged. The TypeScript warnings are pre-existing (unused variables) and don't affect the build.
63 lines
1.5 KiB
TypeScript
63 lines
1.5 KiB
TypeScript
import { v } from "convex/values";
|
|
import { internalQuery } from "./_generated/server";
|
|
|
|
// Internal query to fetch post details by IDs
|
|
export const fetchPostsByIds = internalQuery({
|
|
args: { ids: v.array(v.id("posts")) },
|
|
returns: v.array(
|
|
v.object({
|
|
_id: v.id("posts"),
|
|
slug: v.string(),
|
|
title: v.string(),
|
|
description: v.string(),
|
|
content: v.string(),
|
|
unlisted: v.optional(v.boolean()),
|
|
})
|
|
),
|
|
handler: async (ctx, args) => {
|
|
const results = [];
|
|
for (const id of args.ids) {
|
|
const doc = await ctx.db.get(id);
|
|
if (doc && doc.published && !doc.unlisted) {
|
|
results.push({
|
|
_id: doc._id,
|
|
slug: doc.slug,
|
|
title: doc.title,
|
|
description: doc.description,
|
|
content: doc.content,
|
|
unlisted: doc.unlisted,
|
|
});
|
|
}
|
|
}
|
|
return results;
|
|
},
|
|
});
|
|
|
|
// Internal query to fetch page details by IDs
|
|
export const fetchPagesByIds = internalQuery({
|
|
args: { ids: v.array(v.id("pages")) },
|
|
returns: v.array(
|
|
v.object({
|
|
_id: v.id("pages"),
|
|
slug: v.string(),
|
|
title: v.string(),
|
|
content: v.string(),
|
|
})
|
|
),
|
|
handler: async (ctx, args) => {
|
|
const results = [];
|
|
for (const id of args.ids) {
|
|
const doc = await ctx.db.get(id);
|
|
if (doc && doc.published) {
|
|
results.push({
|
|
_id: doc._id,
|
|
slug: doc.slug,
|
|
title: doc.title,
|
|
content: doc.content,
|
|
});
|
|
}
|
|
}
|
|
return results;
|
|
},
|
|
});
|