Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Schema
✓ import { Schema } from 'ivy-orm'
✗ const Schema = require('ivy-orm').Schema
ESM-only; CommonJS require works for named exports but TypeScript prefers import statement.
SearchService
✓ import { SearchService } from 'ivy-orm'
✗ import SearchService from 'ivy-orm'
Named export, not default. ESM since v0.0.1.
defineIndex
✓ import { defineIndex } from 'ivy-orm'
✗ const { defineIndex } = require('ivy-orm')
Both ESM and CJS work, but ESM is recommended for tree-shaking.
Creates an Azure AI Search index, uploads documents, and performs a search using Ivy ORM schema and Azure SDK.
import { Schema, SearchService } from 'ivy-orm';
import { SearchClient } from '@azure/search-documents';
// Define schema
const productSchema = new Schema('products', {
fields: {
id: { type: 'Edm.String', key: true },
name: { type: 'Edm.String', searchable: true },
price: { type: 'Edm.Double', filterable: true },
},
});
// Initialize service (requires AZURE_SEARCH_ENDPOINT and AZURE_SEARCH_KEY env vars)
const service = new SearchService({
endpoint: process.env.AZURE_SEARCH_ENDPOINT ?? '',
credential: process.env.AZURE_SEARCH_KEY ?? '',
});
async function main() {
await service.createIndex(productSchema);
const client = new SearchClient(service.endpoint, 'products', service.credential);
await client.uploadDocuments([
{ id: '1', name: 'Laptop', price: 999.99 },
{ id: '2', name: 'Mouse', price: 29.99 },
]);
const results = await client.search('laptop');
console.log(results.results);
}
main().catch(console.error);
Debug
Known issues
breakingSchema constructor changed from positional arguments to options object in v0.0.20fixUse new Schema('name', { fields: {...} }) instead of new Schema('name', {...}) affects: <0.0.20
deprecatedSearchService.initialize() is deprecated; use constructor directlyfixUse new SearchService({ endpoint, credential }) instead of service.initialize() affects: >=0.0.15 <0.0.25
gotchaFields without 'key: true' must have a corresponding index definition; otherwise search failsfixAlways define a key field for each index schema
affects: >=0.0.1
gotchaAzure AI Search credentials must be provided with key or token; anonymous access not supportedfixSet AZURE_SEARCH_ENDPOINT and AZURE_SEARCH_KEY environment variables
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: Class extends value undefined is not a constructor or null
Missing '@azure/search-documents' dependency or incorrect import
fixRun 'npm install @azure/search-documents' and ensure the import is correct
Error: [azure-search] The request is invalid. Details: The field 'id' has type 'Edm.String' but no key attribute.
Schema missing key field definitions
fixAdd 'key: true' to the primary key field in the schema
TypeError: Cannot read properties of undefined (reading 'endpoint')
Environment variables not set or service not initialized properly
fixSet AZURE_SEARCH_ENDPOINT and AZURE_SEARCH_KEY, or pass explicitly to SearchService constructor
Audit
Dependencies
@azure/search-documentsrequiredOfficial Azure SDK for AI Search operations