azure-search-documents-ts — Claude Code skill for Azure AI Search
A skill that gives your agent working TypeScript patterns for the Azure AI Search SDK: indexes, vector and hybrid search, semantic ranking.
npx skills add microsoft/skills --skill azure-search-documents-ts -a claude-codeWhat azure-search-documents-ts does
The skill hands the agent ready code samples for @azure/search-documents. It covers index creation with a vector field and HNSW profile, document upload, full-text, vector and hybrid search, semantic ranking with extractive captions and answers, filters and facets, autocomplete through a suggester, and batch upload/merge/delete actions.
You need AZURE_SEARCH_ENDPOINT and AZURE_SEARCH_INDEX_NAME set, plus AZURE_SEARCH_ADMIN_KEY unless you authenticate with Entra ID. Install the packages with npm install @azure/search-documents @azure/identity. When DefaultAzureCredential runs in production, the skill expects AZURE_TOKEN_CREDENTIALS=prod — skip it and the credential chain resolves differently than the samples assume.
Semantic search only works on an index that already has a semanticSearch configuration, and that is set at index creation time. Vector search needs your own embedding function; the SDK does not produce vectors, so you compute them before calling search.
What it helps with
- create an index with a vector field and HNSW profile
- upload documents in batches with uploadDocuments
- combine text and vector queries in hybrid search
- turn on semantic ranking with captions and answers
- build facet counts and filters by category and price
Example prompts for the agent
- show me how to create a products index with an embedding vector field
- write a hybrid search with kNearestNeighborsCount 50
- add semantic ranking with extractive captions to this query
How to install azure-search-documents-ts
1Skills CLI (Vercel)
npx skills add microsoft/skills --skill azure-search-documents-ts -a claude-code2Manually: put the files in place
~/.claude/skills/azure-search-documents-ts/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/azure-search-documents-ts/
Manually: put the files in place
.agents/skills/azure-search-documents-ts/SKILL.mdFor all projects use ~/.agents/skills/
Manually: put the files in place
.cursor/skills/azure-search-documents-ts/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install microsoft/skills azure-search-documents-ts2Manually: put the files in place
.github/skills/azure-search-documents-ts/SKILL.mdPlatform CLI
gemini skills install https://github.com/microsoft/skills --path .github/plugins/azure-sdk-typescript/skills/azure-search-documents-tsManually: put the files in place
.devin/skills/azure-search-documents-ts/SKILL.mdThe legacy .windsurf/skills/ path still works
Claude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about azure-search-documents-ts
How do I install azure-search-documents-ts in Claude?
Run npx skills add microsoft/skills --skill azure-search-documents-ts -a claude-code. The skill lands in ~/.claude/skills/azure-search-documents-ts/SKILL.md.
What does azure-search-documents-ts do?
It guides the agent through TypeScript code for Azure AI Search: index management, vector and hybrid queries, semantic ranking, autocomplete and batch document operations.
What do I need before using it?
The @azure/search-documents and @azure/identity packages, plus AZURE_SEARCH_ENDPOINT and AZURE_SEARCH_INDEX_NAME. AZURE_SEARCH_ADMIN_KEY is required unless you use Entra ID.
Source text
SKILL.md · MIT
---
name: azure-search-documents-ts
description: Build 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.
license: MIT
metadata:
author: Microsoft
version: "1.0.0"
package: '@azure/search-documents'
---
# Azure AI Search SDK for TypeScript
Build search applications with vector, hybrid, and semantic search capabilities.
## Installation
```bash
npm install @azure/search-documents @azure/identity
```
## Environment Variables
```bash
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
```typescript
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
```typescript
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
```typescript
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
```typescript
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
```typescript
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)
```typescript
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
```typescript
// 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
```typescript
// 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
```typescript
// 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
```typescript
// 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
```typescript
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
© Microsoft · MIT · microsoft/skills