MicrosoftBackendSKILL.mdVerified source

Agent Skill

Azure AI Search for TypeScript

Build vector, hybrid, semantic, and agentic retrieval workflows with the Azure AI Search SDK.

azure-ai-searchretrievaltypescript

Skill specification

Declared by Microsoft in the package front matter. Trigger conditions are what the coding agent matches on before it loads the skill.

Azure AI Search for TypeScript SKILL.md front matter fields
Skill nameazure-search-documents-ts
Trigger conditionsBuild search applications using Azure AI Search SDK for JavaScript (@azure/search-documents). Use when creating/managing indexes, implementing vector/hybrid search, semantic ranking, or building agentic retrieval with knowledge bases.
Declared licenseMIT
Version1.0.0
AuthorMicrosoft
Package@azure/search-documents

Install azure-search-documents-ts

Agent Skills are a shared file format, but each client discovers them from a different directory. Copy the command for your agent, then start a new session so the skill is picked up.

Claude Code

.claude/skills/azure-search-documents-ts/SKILL.md

Project skills are committed with the repo. Use the user directory for a personal install across every project.

Project install

mkdir -p .claude/skills/azure-search-documents-ts && curl -fsSL 'https://raw.githubusercontent.com/microsoft/skills/main/.github/plugins/azure-sdk-typescript/skills/azure-search-documents-ts/SKILL.md' -o .claude/skills/azure-search-documents-ts/SKILL.md

Personal install

mkdir -p ~/.claude/skills/azure-search-documents-ts && curl -fsSL 'https://raw.githubusercontent.com/microsoft/skills/main/.github/plugins/azure-sdk-typescript/skills/azure-search-documents-ts/SKILL.md' -o ~/.claude/skills/azure-search-documents-ts/SKILL.md

Codex

.agents/skills/azure-search-documents-ts/SKILL.md

Codex reads `.agents/skills/` as its primary location, which is also the cross-platform default other clients honour.

Project install

mkdir -p .agents/skills/azure-search-documents-ts && curl -fsSL 'https://raw.githubusercontent.com/microsoft/skills/main/.github/plugins/azure-sdk-typescript/skills/azure-search-documents-ts/SKILL.md' -o .agents/skills/azure-search-documents-ts/SKILL.md

Personal install

mkdir -p ~/.agents/skills/azure-search-documents-ts && curl -fsSL 'https://raw.githubusercontent.com/microsoft/skills/main/.github/plugins/azure-sdk-typescript/skills/azure-search-documents-ts/SKILL.md' -o ~/.agents/skills/azure-search-documents-ts/SKILL.md

Cursor

.cursor/skills/azure-search-documents-ts/SKILL.md

Cursor also loads `.agents/skills/`, `.claude/skills/`, and `.codex/skills/`, so one committed copy can serve several clients.

Project install

mkdir -p .cursor/skills/azure-search-documents-ts && curl -fsSL 'https://raw.githubusercontent.com/microsoft/skills/main/.github/plugins/azure-sdk-typescript/skills/azure-search-documents-ts/SKILL.md' -o .cursor/skills/azure-search-documents-ts/SKILL.md

Personal install

mkdir -p ~/.cursor/skills/azure-search-documents-ts && curl -fsSL 'https://raw.githubusercontent.com/microsoft/skills/main/.github/plugins/azure-sdk-typescript/skills/azure-search-documents-ts/SKILL.md' -o ~/.cursor/skills/azure-search-documents-ts/SKILL.md

Gemini CLI

.gemini/skills/azure-search-documents-ts/SKILL.md

Gemini CLI reads `.agents/skills/` first when both directories exist.

Project install

mkdir -p .gemini/skills/azure-search-documents-ts && curl -fsSL 'https://raw.githubusercontent.com/microsoft/skills/main/.github/plugins/azure-sdk-typescript/skills/azure-search-documents-ts/SKILL.md' -o .gemini/skills/azure-search-documents-ts/SKILL.md

Personal install

mkdir -p ~/.gemini/skills/azure-search-documents-ts && curl -fsSL 'https://raw.githubusercontent.com/microsoft/skills/main/.github/plugins/azure-sdk-typescript/skills/azure-search-documents-ts/SKILL.md' -o ~/.gemini/skills/azure-search-documents-ts/SKILL.md

GitHub Copilot

.github/skills/azure-search-documents-ts/SKILL.md

Copilot in VS Code discovers repository skills from `.github/skills/`.

Project install

mkdir -p .github/skills/azure-search-documents-ts && curl -fsSL 'https://raw.githubusercontent.com/microsoft/skills/main/.github/plugins/azure-sdk-typescript/skills/azure-search-documents-ts/SKILL.md' -o .github/skills/azure-search-documents-ts/SKILL.md

Personal install

mkdir -p ~/.copilot/skills/azure-search-documents-ts && curl -fsSL 'https://raw.githubusercontent.com/microsoft/skills/main/.github/plugins/azure-sdk-typescript/skills/azure-search-documents-ts/SKILL.md' -o ~/.copilot/skills/azure-search-documents-ts/SKILL.md

Published by Microsoft under MIT. Rendered from the package in github.com/microsoft/skills/tree/main/.github/plugins/azure-sdk-typescript/skills/azure-search-documents-ts.

Azure AI Search SDK for TypeScript

Build search applications with vector, hybrid, and semantic search capabilities.

Installation

npm install @azure/search-documents @azure/identity

Environment Variables

AZURE_SEARCH_ENDPOINT=https://<service-name>.search.windows.net
AZURE_SEARCH_INDEX_NAME=my-index
AZURE_SEARCH_ADMIN_KEY=<admin-key>  # Optional if using Entra ID
AZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production

Authentication

import { SearchClient, SearchIndexClient } from "@azure/search-documents";
import { DefaultAzureCredential, ManagedIdentityCredential } from "@azure/identity";

const endpoint = process.env.AZURE_SEARCH_ENDPOINT!;
const indexName = process.env.AZURE_SEARCH_INDEX_NAME!;
// Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
const credential = new DefaultAzureCredential({requiredEnvVars: ["AZURE_TOKEN_CREDENTIALS"]});
// Or use a specific credential directly in production:
// See https://learn.microsoft.com/javascript/api/overview/azure/identity-readme?view=azure-node-latest#credential-classes
// const credential = new ManagedIdentityCredential();

// For searching
const searchClient = new SearchClient(endpoint, indexName, credential);

// For index management
const indexClient = new SearchIndexClient(endpoint, credential);

Core Workflow

Create Index with Vector Field

import { SearchIndex, SearchField, VectorSearch } from "@azure/search-documents";

const index: SearchIndex = {
  name: "products",
  fields: [
    { name: "id", type: "Edm.String", key: true },
    { name: "title", type: "Edm.String", searchable: true },
    { name: "description", type: "Edm.String", searchable: true },
    { name: "category", type: "Edm.String", filterable: true, facetable: true },
    {
      name: "embedding",
      type: "Collection(Edm.Single)",
      searchable: true,
      vectorSearchDimensions: 1536,
      vectorSearchProfileName: "vector-profile",
    },
  ],
  vectorSearch: {
    algorithms: [
      { name: "hnsw-algorithm", kind: "hnsw" },
    ],
    profiles: [
      { name: "vector-profile", algorithmConfigurationName: "hnsw-algorithm" },
    ],
  },
};

await indexClient.createOrUpdateIndex(index);

Index Documents

const documents = [
  { id: "1", title: "Widget", description: "A useful widget", category: "Tools", embedding: [...] },
  { id: "2", title: "Gadget", description: "A cool gadget", category: "Electronics", embedding: [...] },
];

const result = await searchClient.uploadDocuments(documents);
console.log(`Indexed ${result.results.length} documents`);

Full-Text Search

const results = await searchClient.search("widget", {
  select: ["id", "title", "description"],
  filter: "category eq 'Tools'",
  orderBy: ["title asc"],
  top: 10,
});

for await (const result of results.results) {
  console.log(`${result.document.title}: ${result.score}`);
}

Vector Search

const queryVector = await getEmbedding("useful tool"); // Your embedding function

const results = await searchClient.search("*", {
  vectorSearchOptions: {
    queries: [
      {
        kind: "vector",
        vector: queryVector,
        fields: ["embedding"],
        kNearestNeighborsCount: 10,
      },
    ],
  },
  select: ["id", "title", "description"],
});

for await (const result of results.results) {
  console.log(`${result.document.title}: ${result.score}`);
}

Hybrid Search (Text + Vector)

const queryVector = await getEmbedding("useful tool");

const results = await searchClient.search("tool", {
  vectorSearchOptions: {
    queries: [
      {
        kind: "vector",
        vector: queryVector,
        fields: ["embedding"],
        kNearestNeighborsCount: 50,
      },
    ],
  },
  select: ["id", "title", "description"],
  top: 10,
});

Semantic Search

// Index must have semantic configuration
const index: SearchIndex = {
  name: "products",
  fields: [...],
  semanticSearch: {
    configurations: [
      {
        name: "semantic-config",
        prioritizedFields: {
          titleField: { name: "title" },
          contentFields: [{ name: "description" }],
        },
      },
    ],
  },
};

// Search with semantic ranking
const results = await searchClient.search("best tool for the job", {
  queryType: "semantic",
  semanticSearchOptions: {
    configurationName: "semantic-config",
    captions: { captionType: "extractive" },
    answers: { answerType: "extractive", count: 3 },
  },
  select: ["id", "title", "description"],
});

for await (const result of results.results) {
  console.log(`${result.document.title}`);
  console.log(`  Caption: ${result.captions?.[0]?.text}`);
  console.log(`  Reranker Score: ${result.rerankerScore}`);
}

Filtering and Facets

// Filter syntax
const results = await searchClient.search("*", {
  filter: "category eq 'Electronics' and price lt 100",
  facets: ["category,count:10", "brand"],
});

// Access facets
for (const [facetName, facetResults] of Object.entries(results.facets || {})) {
  console.log(`${facetName}:`);
  for (const facet of facetResults) {
    console.log(`  ${facet.value}: ${facet.count}`);
  }
}

Autocomplete and Suggestions

// Create suggester in index
const index: SearchIndex = {
  name: "products",
  fields: [...],
  suggesters: [
    { name: "sg", sourceFields: ["title", "description"] },
  ],
};

// Autocomplete
const autocomplete = await searchClient.autocomplete("wid", "sg", {
  mode: "twoTerms",
  top: 5,
});

// Suggestions
const suggestions = await searchClient.suggest("wid", "sg", {
  select: ["title"],
  top: 5,
});

Batch Operations

// Batch upload, merge, delete
const batch = [
  { upload: { id: "1", title: "New Item" } },
  { merge: { id: "2", title: "Updated Title" } },
  { delete: { id: "3" } },
];

const result = await searchClient.indexDocuments({ actions: batch });

Key Types

import {
  SearchClient,
  SearchIndexClient,
  SearchIndexerClient,
  SearchIndex,
  SearchField,
  SearchOptions,
  VectorSearch,
  SemanticSearch,
  SearchIterator,
} from "@azure/search-documents";

Best Practices

  1. Use hybrid search - Combine vector + text for best results
  2. Enable semantic ranking - Improves relevance for natural language queries
  3. Batch document uploads - Use uploadDocuments with arrays, not single docs
  4. Use filters for security - Implement document-level security with filters
  5. Index incrementally - Use mergeOrUploadDocuments for updates
  6. Monitor query performance - Use includeTotalCount: true sparingly in production

Add the registry badge

Maintainers can link this listing from the skill's own README. Free, no account needed, and it points back at the rendered package for anyone browsing the repo.

Markdown

[![Azure AI Search for TypeScript on tokens&](https://tokensand.com/api/badges/skill/microsoft-azure-search-documents-ts)](https://tokensand.com/agent-skills/microsoft-azure-search-documents-ts)

HTML

<a href="https://tokensand.com/agent-skills/microsoft-azure-search-documents-ts" target="_blank" rel="noopener">
  <img src="https://tokensand.com/api/badges/skill/microsoft-azure-search-documents-ts" alt="Azure AI Search for TypeScript on tokens&" />
</a>

More Microsoft Agent Skills

All Agent Skills