async function main()

in demo-javascript/code/azure-search-vector-sample.js [11:71]


async function main() {
  program
    .option('-e, --embed', 'Recreate embeddings in text-sample.json')
    .option('-u, --upload', 'Upload embeddings and data in text-sample.json to the search index')
    .option('-q, --query <text>', 'Text of query to issue to search, if any')
    .addOption(new Option('-k, --query-kind <kind>', 'Kind of query to issue. Defaults to hybrid').default('hybrid').choices(['text', 'vector', 'hybrid']))
    .option('-c, --category-filter <category>', 'Category to filter results to')
    .option('-t, --include-title', 'Search over the title field as well as the content field')
    .option('--no-semantic-reranker', 'Do not use semantic reranker. Defaults to false')
    .parse();

  const options = program.opts()
  const defaultCredential = new DefaultAzureCredential();

  // Load environment variables from .env file
  dotenv.config({ path: "../.env" });

  // Generate document embeddings
  if (options.embed) {
    try {
      await generateDocumentEmbeddings(defaultCredential);
    } catch (err) {
      console.error(
        `Failed to generate embeddings: ${err.message}`
      );
      return;
    }
  }

  // Upload documents to Azure AI Search
  if (options.upload) {
    // Create Azure AI Search index
    try {
      await createSearchIndex(defaultCredential);
    } catch (err) {
      console.error(`Failed to create index: ${err.message}`);
      return;
    }

    try {
      await uploadDocuments(defaultCredential);
    } catch (err) {
      console.error(
        `Failed to upload documents to search index: ${err.message}`
      );
      return;
    }
  }

  // Query Azure AI Search
  if (options.query) {
    try {
      await queryDocuments(defaultCredential, options.query, options.queryKind, options.categoryFilter, options.includeTitle, options.semanticReranker);
    } catch (err) {
      console.error(
        `Failed to issue query to search index: ${err.message}`
      );
      return;
    }
  }
}