Skip to content

Ai enhancements#495

Draft
alexander-sei wants to merge 14 commits intomainfrom
ai-enhancements
Draft

Ai enhancements#495
alexander-sei wants to merge 14 commits intomainfrom
ai-enhancements

Conversation

@alexander-sei
Copy link
Collaborator

What is the purpose of the change?

Describe the changes to the documentation

Notes

@vercel
Copy link

vercel bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sei-docs Ready Ready Preview, Comment Mar 23, 2026 2:05am

Request Review

Convert the docs search implementation to use synchronous file I/O and simplify token handling. loadSections() is now synchronous and uses readdirSync/readFileSync; DocSection no longer stores a tokens array and DF computation uses tokenFreq keys. Miscellaneous cleanups include compacting the STOP_WORDS list, inlining section object construction, tightening the BM25 term calculation, simplifying snippet extraction, and small control-flow consolidations. Also updated next.config.mjs to add outputFileTracingIncludes for the /api/chat and /api/mcp routes so the scraped docs are included in tracing.
Add a build script to generate a precomputed search index (scripts/build-search-index.js -> lib/search-index.json) and switch search code to load that JSON at runtime. This removes runtime scraping of public/_scraped-docs, converts tokenFreq to plain records, adds an index cache, refactors BM25/snippet logic, and improves performance and tracing. Also: update next.config to include lib/search-index.json in outputFileTracingIncludes, add lib/search-index.json to .gitignore, and invoke the index build in postbuild.
Improve resilience of search index loading and building. - lib/search-docs.ts: add EMPTY_INDEX and wrap loadIndex in try/catch with validation to return an empty index on missing/invalid search-index.json. - scripts/build-search-index.js: add CONTENT_DIR and helpers (stripMdxNoise, parseYamlScalar, parseSourceMdx, relPathToDocsUrl, walkContentMdxFiles) to parse content/*.mdx, strip MDX import/export noise, and extract frontmatter. Split section building into scraped and content flows, log counts, and fall back to content MDX when scraped docs are absent (avoids Vercel build failures). Add better error handling and messages when no sections are found.
Improve search tokenization and phrase handling, update build index tokenizer, and significantly enhance the AI assistant UI and state persistence. Search: refine tokenize regex (split on spaces/underscores/hyphens), add normalizeQueryText, foldForPhraseMatch, expandUnknownCompoundTokens, and phrase-folding boosts for title/heading matches to better handle run-together/camelCase/underscore queries. scripts/build-search-index.js updated to match tokenization. AIAssistant: add persistent active session storage, archived chat history with a popover, recent queries, randomized starter question pool, new-chat archiving behavior, panel resize with saved width, multiple UX improvements (copy reply button, code block copy, improved selection/cursor behavior), accessibility attributes, and various localStorage guards. Minor: small clarification to system prompt examples in app/api/chat/route.ts.
Enhance search reliability and index building: update the system prompt and API behavior to encourage wallet/network keyword retries and to allow answering from key context when docs are missing. In lib/search-docs.ts add a substringFallbackRank to match raw query words when BM25 yields zero, handle empty queries early, and refactor result construction to reuse snippet logic and fall back to substring matches. In scripts/build-search-index.js prefer content/ sections over scraped HTML by merging sets (and log merge stats), ensuring the index uses up-to-date content when available.
Remove dead vector search integration that was never functional
(doc-embeddings.json was never generated). Inline SearchResult
type back into search-docs.ts.

Made-with: Cursor
Add resolveIndexPath to lib/search-docs.ts to locate search-index.json from several candidate locations (project lib, module directory, .next/server/lib). Update imports to use fileURLToPath and dirname and use existsSync with error-safe checks. loadIndex now uses the resolver and falls back to an EMPTY_INDEX if no index file is found. Update package.json build script to run scripts/build-search-index.js before the Next.js build so the index is generated during build.
Introduce an "Ask AI about this page" action in the ContextualMenu: adds an AskAI icon, click handler that dispatches a 'sei-ask-ai' CustomEvent (with pagePath, pageTitle, markdownUrl), visual highlight and separator, and imports Fragment for markup. Update contextual menu CSS to cap dropdown height, enable scrolling, and style the Ask AI highlight and separator. In AIAssistant, add an event listener for 'sei-ask-ai' to open the assistant and automatically send a contextual question (based on the page title). Minor UI/UX wiring to connect the menu action to the assistant.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants