Skip to main content

vai generate

Generate production-ready code snippets for integrating Voyage AI embeddings and MongoDB Atlas Vector Search into your application.

Synopsis​

vai generate <component> [options]

Description​

vai generate creates code files for specific components of a RAG integration. It reads your .vai.json project config to populate the generated code with your actual model, database, collection, and field names.

Components​

ComponentDescription
clientVoyage AI client initialization
connectionMongoDB connection setup
retrievalVector search retrieval logic
ingestDocument ingestion pipeline
search-apiSearch API endpoint

Targets​

TargetFrameworkOutput
vanillaPlain Node.jslib/*.js files
nextjsNext.js (App Router)Routes, pages, lib files
pythonPython (Flask)Python modules

Options​

FlagDescriptionDefault
<component>Component to generate (required)—
-t, --target <target>Target frameworkAuto-detected or vanilla
-o, --output <path>Output file pathDefault per component
-m, --model <model>Override model in generated codeFrom .vai.json
--db <database>Override database nameFrom .vai.json
--collection <name>Override collectionFrom .vai.json
--field <name>Override embedding fieldFrom .vai.json
--no-rerankOmit reranking from generated code—
--dry-runShow generated code without writing—
--jsonOutput as JSON—
-q, --quietSuppress non-essential output—

Examples​

Generate a retrieval module​

vai generate retrieval

Generate for Next.js​

vai generate search-api --target nextjs

Generate Python client​

vai generate client --target python

Preview without writing​

vai generate ingest --dry-run

Tips​

  • Auto-detection checks for next.config.js, requirements.txt, etc. to pick the right target.
  • Run vai init first so generated code uses your project's actual settings.
  • For complete starter projects (multiple files + package.json), use vai scaffold instead.