@azure/search-documents 12.0.0-beta.1 → 12.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/README.md +56 -15
  2. package/dist/index.js +595 -139
  3. package/dist/index.js.map +1 -1
  4. package/dist-esm/src/constants.js +1 -1
  5. package/dist-esm/src/constants.js.map +1 -1
  6. package/dist-esm/src/generated/data/models/index.js +50 -6
  7. package/dist-esm/src/generated/data/models/index.js.map +1 -1
  8. package/dist-esm/src/generated/data/models/mappers.js +202 -0
  9. package/dist-esm/src/generated/data/models/mappers.js.map +1 -1
  10. package/dist-esm/src/generated/data/models/parameters.js +30 -0
  11. package/dist-esm/src/generated/data/models/parameters.js.map +1 -1
  12. package/dist-esm/src/generated/data/operations/documents.js +3 -0
  13. package/dist-esm/src/generated/data/operations/documents.js.map +1 -1
  14. package/dist-esm/src/generated/data/searchClient.js +1 -1
  15. package/dist-esm/src/generated/data/searchClient.js.map +1 -1
  16. package/dist-esm/src/generated/service/models/index.js +15 -14
  17. package/dist-esm/src/generated/service/models/index.js.map +1 -1
  18. package/dist-esm/src/generated/service/models/mappers.js +190 -7
  19. package/dist-esm/src/generated/service/models/mappers.js.map +1 -1
  20. package/dist-esm/src/generated/service/searchServiceClient.js +1 -1
  21. package/dist-esm/src/generated/service/searchServiceClient.js.map +1 -1
  22. package/dist-esm/src/index.js.map +1 -1
  23. package/dist-esm/src/indexModels.js.map +1 -1
  24. package/dist-esm/src/searchClient.js +51 -57
  25. package/dist-esm/src/searchClient.js.map +1 -1
  26. package/dist-esm/src/searchIndexClient.js +5 -16
  27. package/dist-esm/src/searchIndexClient.js.map +1 -1
  28. package/dist-esm/src/searchIndexerClient.js +0 -11
  29. package/dist-esm/src/searchIndexerClient.js.map +1 -1
  30. package/dist-esm/src/searchIndexingBufferedSender.js.map +1 -1
  31. package/dist-esm/src/serviceModels.js.map +1 -1
  32. package/dist-esm/src/serviceUtils.js +39 -26
  33. package/dist-esm/src/serviceUtils.js.map +1 -1
  34. package/package.json +14 -5
  35. package/types/search-documents.d.ts +469 -110
package/README.md CHANGED
@@ -318,19 +318,24 @@ main();
318
318
 
319
319
  #### Querying with TypeScript
320
320
 
321
- In TypeScript `SearchClient` takes a generic parameter that is the model shape of your index documents. This allows you to perform strongly typed lookup of fields returned in results. TypeScript is also able to check for fields returned when specifying a `select` parameter.
321
+ In TypeScript, `SearchClient` takes a generic parameter that is the model shape of your index documents. This allows you to perform strongly typed lookup of fields returned in results. TypeScript is also able to check for fields returned when specifying a `select` parameter.
322
322
 
323
323
  ```ts
324
324
  import { SearchClient, AzureKeyCredential } from "@azure/search-documents";
325
325
 
326
326
  // An example schema for documents in the index
327
327
  interface Hotel {
328
- HotelId: string;
329
- HotelName: string;
330
- Description: string;
331
- ParkingIncluded: boolean;
332
- LastRenovationDate: Date;
333
- Rating: number;
328
+ hotelId?: string;
329
+ hotelName?: string | null;
330
+ description?: string | null;
331
+ descriptionVector?: Array<number> | null;
332
+ parkingIncluded?: boolean | null;
333
+ lastRenovationDate?: Date | null;
334
+ rating?: number | null;
335
+ rooms?: Array<{
336
+ beds?: number | null;
337
+ description?: string | null;
338
+ } | null;>
334
339
  }
335
340
 
336
341
  const client = new SearchClient<Hotel>(
@@ -343,13 +348,22 @@ async function main() {
343
348
  const searchResults = await client.search("wifi -luxury", {
344
349
  // Only fields in Hotel can be added to this array.
345
350
  // TS will complain if one is misspelled.
346
- select: ["HotelId", "HotelName", "Rating"],
351
+ select: ["hotelId", "hotelName", "rooms/beds"],
347
352
  });
348
353
 
354
+ // These are other ways to declare the correct type for `select`.
355
+ const select = ["hotelId", "hotelName", "rooms/beds"] as const;
356
+ // This declaration lets you opt out of narrowing the TypeScript type of your documents,
357
+ // though the Cognitive Search service will still only return these fields.
358
+ const selectWide: SelectFields<Hotel>[] = ["hotelId", "hotelName", "rooms/beds"];
359
+ // This is an invalid declaration. Passing this to `select` will result in a compiler error
360
+ // unless you opt out of including the model in the client constructor.
361
+ const selectInvalid = ["hotelId", "hotelName", "rooms/beds"];
362
+
349
363
  for await (const result of searchResults.results) {
350
- // result.document has HotelId, HotelName, and Rating.
351
- // Trying to access result.document.Description would emit a TS error.
352
- console.log(result.document.HotelName);
364
+ // result.document has hotelId, hotelName, and rating.
365
+ // Trying to access result.document.description would emit a TS error.
366
+ console.log(result.document.hotelName);
353
367
  }
354
368
  }
355
369
 
@@ -371,7 +385,7 @@ async function main() {
371
385
  const searchResults = await client.search("WiFi", {
372
386
  filter: odata`Rooms/any(room: room/BaseRate lt ${baseRateMax}) and Rating ge ${ratingMin}`,
373
387
  orderBy: ["Rating desc"],
374
- select: ["HotelId", "HotelName", "Rating"],
388
+ select: ["hotelId", "hotelName", "rating"],
375
389
  });
376
390
  for await (const result of searchResults.results) {
377
391
  // Each result will have "HotelId", "HotelName", and "Rating"
@@ -383,6 +397,33 @@ async function main() {
383
397
  main();
384
398
  ```
385
399
 
400
+ #### Querying with vectors
401
+
402
+ Text embeddings can be queried using the `vector` search parameter.
403
+
404
+ ```js
405
+ const { SearchClient, AzureKeyCredential, odata } = require("@azure/search-documents");
406
+
407
+ const client = new SearchClient("<endpoint>", "<indexName>", new AzureKeyCredential("<apiKey>"));
408
+
409
+ async function main() {
410
+ const queryVector: number[] = [...]
411
+ const searchResults = await searchClient.search("*", {
412
+ vector: {
413
+ fields: ["descriptionVector"],
414
+ kNearestNeighborsCount: 3,
415
+ value: queryVector,
416
+ },
417
+ });
418
+ for await (const result of searchResults.results) {
419
+ // These results are the nearest neighbors to the query vector
420
+ console.log(result);
421
+ }
422
+ }
423
+
424
+ main();
425
+ ```
426
+
386
427
  #### Querying with facets
387
428
 
388
429
  [Facets](https://docs.microsoft.com/azure/search/search-filters-facets) are used to help a user of your application refine a search along pre-configured dimensions. [Facet syntax](https://docs.microsoft.com/rest/api/searchservice/search-documents#facetstring-zero-or-more) provides the options to sort and bucket facet values.
@@ -394,17 +435,17 @@ const client = new SearchClient("<endpoint>", "<indexName>", new AzureKeyCredent
394
435
 
395
436
  async function main() {
396
437
  const searchResults = await client.search("WiFi", {
397
- facets: ["Category,count:3,sort:count", "Rooms/BaseRate,interval:100"],
438
+ facets: ["category,count:3,sort:count", "rooms/baseRate,interval:100"],
398
439
  });
399
440
  console.log(searchResults.facets);
400
441
  // Output will look like:
401
442
  // {
402
- // 'Rooms/BaseRate': [
443
+ // 'rooms/baseRate': [
403
444
  // { count: 16, value: 0 },
404
445
  // { count: 17, value: 100 },
405
446
  // { count: 17, value: 200 }
406
447
  // ],
407
- // Category: [
448
+ // category: [
408
449
  // { count: 5, value: 'Budget' },
409
450
  // { count: 5, value: 'Luxury' },
410
451
  // { count: 5, value: 'Resort and Spa' }