npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

azure-ai-search-orm

v0.0.20

Published

A fully type-safe "ORM" for Azure AI Search (formerly Cognitive Search) inspired by Drizzle ORM.

Downloads

24

Readme

Azure AI Search ORM

A fully type-safe "ORM" for Azure AI Search (formerly Cognitive Search) inspired by Drizzle ORM.

Define a fluent schema:

import { string, index, int32 } from "orm/schema";

export const realEstate = index("realestate-us-sample-index", {
  listingId: string("listingId").key(),
  beds: int32("beds").filterable().sortable().facetable(),
  baths: int32("baths").filterable().sortable().facetable(),
  description: string("description").searchable(),
  squareFeet: int32("sqft").filterable().sortable().facetable(),
});

and use all the methods you'd usually use on a SearchClient, but with excellent TypeScript support:

const searchIndexClient = new SearchIndexClient(endpoint, identity);

const srch = connect(searchIndexClient, schema);

const data = await srch.realEstate.search(undefined, {
  top: 20,
  select: ["listingId", "description"],
});

Supported Field Types

Azure AI Search ORM supports most of the AI Search EDM data types.

Primitives

// Edm.String
myField: string("myField");

// Edm.Int32
myField: int32("myField");

// Edm.Int64
myField: int64("myField");

//Edm.Double
myField: double("myField");

//Edm.Boolean
myField: boolean("myField");

Collections

// Collection(Edm.String)
myCollection: stringCollection("myCollection");

// Collection(Edm.Int32)
myCollection: int32Collection("myCollection");

// Collection(Edm.Int64)
myCollection: int64Collection("myCollection");

// Collection(Edm.Double)
myCollection: doubleCollection("myCollection");

// Collection(Edm.DateTimeOffset)
myCollection: dateCollection("myCollection");

// Collection(Edm.Boolean)
myCollection: booleanCollection("myCollection");

// Collection(Edm.ComplexType)
myCollection: collection("myCollection", {
  // ComplexType object fields
  myField: string("myField"),
});

Suggesters

Add a suggester to a field in the index schema:

import { index, string } from "azure-ai-search-orm";

const hotels = index("hotels-sample-index", {
  name: string("name").suggester(),
});

and use AI Search's suggest() method with Typescript:

const { results } = await srch.hotels.suggest("my query", "sg", {
  select: ["name"],
  searchFields: ["name"],
});

"sg" is the default suggester name.

Extras

Field names in the ORM don't need to match the names in the datasource. This automatically creates a field mapping in the indexer.

export const realEstate = index("realestate-us-sample-index", {
  squareFeet: int32("sqft").filterable().sortable().facetable(),
  // ^ORM field name  ^datasource column name
});

Note: This only works on top-level primitives. Complex fields aren't supported in a field mapping.