Container class

Adott, meglévő tárolók beolvasására, cseréjére vagy törlésére szolgáló műveletek azonosító alapján.

Lásd: Tárolók új tárolók létrehozásához és az összes tároló olvasásához/lekérdezéséhez; .containershasználata.

Megjegyzés: ezek a műveletek rögzített költségvetéssel kapcsolatos hívásokat hajtanak végre. Úgy kell megterveznie a rendszert, hogy ezek a hívások az alkalmazással együtt alkonyatosan skálázhatók legyenek. Például ne hívjon container(id).read() minden egyes item.read() hívás előtt, hogy a tároló létezik-e; ezt egyszer kell elvégeznie az alkalmazás indításakor.

Tulajdonságok

conflicts

Az adott tárolóhoz tartozó ütközések olvasására és lekérdezésére szolgáló műveletek.

Egy adott ütközés olvasásához vagy törléséhez használja a .conflict(id).

database
id
items

Új elemek létrehozására és az összes elem olvasására/lekérdezésére szolgáló műveletek

Meglévő elem olvasásához, cseréjéhez vagy törléséhez használja a .item(id).

példa

Új elem létrehozása

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resource: createdItem } = await container.items.create({
  id: "<item id>",
  properties: {},
});
scripts

Tárolt eljárások, triggerek és felhasználó által definiált függvények összes művelete

url

Az erőforrás hivatkozási URL-címét adja vissza. Az engedélyek csatolásához használatos.

Metódusok

conflict(string, PartitionKey)

Egy adott, meglévő ütközési azonosító alapján történő olvasására, cseréjére vagy törlésére szolgál.

Használja a .conflicts új ütközések létrehozásához, vagy az összes ütközés lekérdezéséhez/olvasásához.

példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const container = database.container("Test Container");

const { resource: conflict } = await container.conflict("<conflict-id>").read();
delete(RequestOptions)

A tároló törlése

példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

await client.database("<db id>").container("<container id>").delete();
deleteAllItemsForPartitionKey(PartitionKey, RequestOptions)

A megadott partíciókulcs-érték tárolójának összes dokumentumának törlése

példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({
  id: "Test Container",
  partitionKey: {
    paths: ["/state"],
  },
});

const cities = [
  { id: "1", name: "Olympia", state: "WA", isCapitol: true },
  { id: "2", name: "Redmond", state: "WA", isCapitol: false },
  { id: "3", name: "Olympia", state: "IL", isCapitol: false },
];
for (const city of cities) {
  await container.items.create(city);
}

await container.deleteAllItemsForPartitionKey("WA");
getFeedRanges()

példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resources: ranges } = await container.getFeedRanges();
getPartitionKeyDefinition()

Először lekéri a partíciókulcs definícióját úgy, hogy a gyűjtemény olvasásával megkeresi a gyorsítótárat.

getQueryPlan(string | SqlQuerySpec)
initializeEncryption()

Bemelegíti a tároló titkosítással kapcsolatos gyorsítótárait.

példa

import { ClientSecretCredential } from "@azure/identity";
import {
  AzureKeyVaultEncryptionKeyResolver,
  CosmosClient,
  EncryptionType,
  EncryptionAlgorithm,
  ClientEncryptionIncludedPath,
  ClientEncryptionPolicy,
} from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const credentials = new ClientSecretCredential("<tenant-id>", "<client-id>", "<app-secret>");
const keyResolver = new AzureKeyVaultEncryptionKeyResolver(credentials);
const client = new CosmosClient({
  endpoint,
  key,
  clientEncryptionOptions: {
    keyEncryptionKeyResolver: keyResolver,
  },
});
const { database } = await client.databases.createIfNotExists({ id: "<db id>" });

const paths = ["/path1", "/path2", "/path3"].map(
  (path) =>
    ({
      path: path,
      clientEncryptionKeyId: "< cek - id >",
      encryptionType: EncryptionType.DETERMINISTIC,
      encryptionAlgorithm: EncryptionAlgorithm.AEAD_AES_256_CBC_HMAC_SHA256,
    }) as ClientEncryptionIncludedPath,
);
const clientEncryptionPolicy: ClientEncryptionPolicy = {
  includedPaths: paths,
  policyFormatVersion: 2,
};
const containerDefinition = {
  id: "Test Container",
  partitionKey: {
    paths: ["/id"],
  },
  clientEncryptionPolicy: clientEncryptionPolicy,
};
const { container } = await database.containers.createIfNotExists(containerDefinition);

await container.initializeEncryption();
item(string, PartitionKey)

Egy adott, meglévő elem olvasására, cseréjére vagy törlésére szolgál, azonosító alapján.

Használja a .items új elemek létrehozásához, vagy az összes elem lekérdezéséhez/olvasásához.

példa

Elem cseréje

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { body: replacedItem } = await container
  .item("<item id>", "<partition key value>")
  .replace({ id: "<item id>", title: "Updated post", authorID: 5 });
read(RequestOptions)

A tároló definíciójának olvasása

példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { resource: database } = await client.database("<db id>").container("<container id>").read();
readOffer(RequestOptions)

Ajánlatot kap a tárolón. Ha nincs ilyen, akkor egy nem definiált OfferResponse értéket ad vissza.

példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { resource: offer } = await client
  .database("<db id>")
  .container("<container id>")
  .readOffer();
readPartitionKeyRanges(FeedOptions)

Lekéri a tároló partíciókulcs-tartományait.

példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resources: ranges } = await container.readPartitionKeyRanges().fetchAll();
replace(ContainerDefinition, RequestOptions)

A tároló definíciójának cseréje

példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const containerDefinition = {
  id: "Test Container",
  partitionKey: {
    paths: ["/key1"],
  },
  throughput: 1000,
};
const { container } = await database.containers.createIfNotExists(containerDefinition);

containerDefinition.throughput = 400;
const { container: replacedContainer } = await container.replace(containerDefinition);
semanticRerank(string, string[], SemanticRerankOptions)

Rangsorolj újra egy dokumentumlistát szemantikai rangsorolással a Cosmos DB Inference Service-en keresztül. Ez a módszer szemantikai újrarangsorolást használ, hogy a megadott dokumentumokat pontozza és átrendezze azok relevanciájuk alapján az adott kontextussal.

A szemantikai újrarangoló kérések külön HTTP pipeline-t használnak a fő Cosmos DB klienstől, és nem használják az alapértelmezett SDK újrapróbálási szabályzatokat.

A funkció használatához a következőket kell tennie:

  1. AAD hitelesítés konfigurálása a aadCredentialsCosmosClientOptions
  2. A következtetés végpontot az in -en enablePreviewFeatures.semanticRerank.inferenceEndpoint keresztül adjuk meg CosmosClientOptions

példa

A lekérdezési eredmények szemantikai újrarangsorolását

import { DefaultAzureCredential } from "@azure/identity";
import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const aadCredentials = new DefaultAzureCredential();
const client = new CosmosClient({
  endpoint,
  aadCredentials,
  enablePreviewFeatures: {
    semanticRerank: {
      inferenceEndpoint: "https://your-account.<region>.dbinference.azure.com",
    },
  },
});

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const queryResults = ["doc1 JSON", "doc2 JSON", "doc3 JSON"];
const result = await container.semanticRerank(
  "most economical with multiple adjustments",
  queryResults,
  { return_documents: true, top_k: 10, sort: true },
);
// Access the top-ranked document
if (result.rerankScores.length > 0) {
  const topResult = result.rerankScores[0];
  const topScore = topResult.score;
  const topDocument = topResult.document;
  if (topDocument) {
    console.log("Top-ranked document:", topDocument);
  }
  console.log("Top score:", topScore);
}

Tulajdonság adatai

conflicts

Az adott tárolóhoz tartozó ütközések olvasására és lekérdezésére szolgáló műveletek.

Egy adott ütközés olvasásához vagy törléséhez használja a .conflict(id).

Conflicts conflicts

Tulajdonság értéke

database

database: Database

Tulajdonság értéke

id

id: string

Tulajdonság értéke

string

items

Új elemek létrehozására és az összes elem olvasására/lekérdezésére szolgáló műveletek

Meglévő elem olvasásához, cseréjéhez vagy törléséhez használja a .item(id).

példa

Új elem létrehozása

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resource: createdItem } = await container.items.create({
  id: "<item id>",
  properties: {},
});
Items items

Tulajdonság értéke

scripts

Tárolt eljárások, triggerek és felhasználó által definiált függvények összes művelete

Scripts scripts

Tulajdonság értéke

url

Az erőforrás hivatkozási URL-címét adja vissza. Az engedélyek csatolásához használatos.

string url

Tulajdonság értéke

string

Metódus adatai

conflict(string, PartitionKey)

Egy adott, meglévő ütközési azonosító alapján történő olvasására, cseréjére vagy törlésére szolgál.

Használja a .conflicts új ütközések létrehozásához, vagy az összes ütközés lekérdezéséhez/olvasásához.

példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });
const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const container = database.container("Test Container");

const { resource: conflict } = await container.conflict("<conflict-id>").read();
function conflict(id: string, partitionKey?: PartitionKey): Conflict

Paraméterek

id

string

A Ütközésazonosítója.

partitionKey
PartitionKey

Válaszok

delete(RequestOptions)

A tároló törlése

példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

await client.database("<db id>").container("<container id>").delete();
function delete(options?: RequestOptions): Promise<ContainerResponse>

Paraméterek

options
RequestOptions

Válaszok

deleteAllItemsForPartitionKey(PartitionKey, RequestOptions)

A megadott partíciókulcs-érték tárolójának összes dokumentumának törlése

példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({
  id: "Test Container",
  partitionKey: {
    paths: ["/state"],
  },
});

const cities = [
  { id: "1", name: "Olympia", state: "WA", isCapitol: true },
  { id: "2", name: "Redmond", state: "WA", isCapitol: false },
  { id: "3", name: "Olympia", state: "IL", isCapitol: false },
];
for (const city of cities) {
  await container.items.create(city);
}

await container.deleteAllItemsForPartitionKey("WA");
function deleteAllItemsForPartitionKey(partitionKey: PartitionKey, options?: RequestOptions): Promise<ContainerResponse>

Paraméterek

partitionKey
PartitionKey

A törölni kívánt elemek partíciókulcs-értéke

options
RequestOptions

Válaszok

getFeedRanges()

példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resources: ranges } = await container.getFeedRanges();
function getFeedRanges(): Promise<readonly FeedRange[]>

Válaszok

Promise<readonly FeedRange[]>

az összes olyan hírcsatornatartomány, amelyhez a változáscsatorna beolvasható.

getPartitionKeyDefinition()

Figyelmeztetés

Ez az API már elavult.

This method has been renamed to readPartitionKeyDefinition.

Először lekéri a partíciókulcs definícióját úgy, hogy a gyűjtemény olvasásával megkeresi a gyorsítótárat.

function getPartitionKeyDefinition(): Promise<ResourceResponse<PartitionKeyDefinition>>

Válaszok

getQueryPlan(string | SqlQuerySpec)

function getQueryPlan(query: string | SqlQuerySpec): Promise<Response<PartitionedQueryExecutionInfo>>

Paraméterek

query

string | SqlQuerySpec

Válaszok

Promise<Response<PartitionedQueryExecutionInfo>>

initializeEncryption()

Bemelegíti a tároló titkosítással kapcsolatos gyorsítótárait.

példa

import { ClientSecretCredential } from "@azure/identity";
import {
  AzureKeyVaultEncryptionKeyResolver,
  CosmosClient,
  EncryptionType,
  EncryptionAlgorithm,
  ClientEncryptionIncludedPath,
  ClientEncryptionPolicy,
} from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const credentials = new ClientSecretCredential("<tenant-id>", "<client-id>", "<app-secret>");
const keyResolver = new AzureKeyVaultEncryptionKeyResolver(credentials);
const client = new CosmosClient({
  endpoint,
  key,
  clientEncryptionOptions: {
    keyEncryptionKeyResolver: keyResolver,
  },
});
const { database } = await client.databases.createIfNotExists({ id: "<db id>" });

const paths = ["/path1", "/path2", "/path3"].map(
  (path) =>
    ({
      path: path,
      clientEncryptionKeyId: "< cek - id >",
      encryptionType: EncryptionType.DETERMINISTIC,
      encryptionAlgorithm: EncryptionAlgorithm.AEAD_AES_256_CBC_HMAC_SHA256,
    }) as ClientEncryptionIncludedPath,
);
const clientEncryptionPolicy: ClientEncryptionPolicy = {
  includedPaths: paths,
  policyFormatVersion: 2,
};
const containerDefinition = {
  id: "Test Container",
  partitionKey: {
    paths: ["/id"],
  },
  clientEncryptionPolicy: clientEncryptionPolicy,
};
const { container } = await database.containers.createIfNotExists(containerDefinition);

await container.initializeEncryption();
function initializeEncryption(): Promise<void>

Válaszok

Promise<void>

item(string, PartitionKey)

Egy adott, meglévő elem olvasására, cseréjére vagy törlésére szolgál, azonosító alapján.

Használja a .items új elemek létrehozásához, vagy az összes elem lekérdezéséhez/olvasásához.

példa

Elem cseréje

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { body: replacedItem } = await container
  .item("<item id>", "<partition key value>")
  .replace({ id: "<item id>", title: "Updated post", authorID: 5 });
function item(id: string, partitionKeyValue?: PartitionKey): Item

Paraméterek

id

string

Az Elemazonosítója.

partitionKeyValue
PartitionKey

A Elem partíciókulcs értéke

Válaszok

read(RequestOptions)

A tároló definíciójának olvasása

példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { resource: database } = await client.database("<db id>").container("<container id>").read();
function read(options?: RequestOptions): Promise<ContainerResponse>

Paraméterek

options
RequestOptions

Válaszok

readOffer(RequestOptions)

Ajánlatot kap a tárolón. Ha nincs ilyen, akkor egy nem definiált OfferResponse értéket ad vissza.

példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { resource: offer } = await client
  .database("<db id>")
  .container("<container id>")
  .readOffer();
function readOffer(options?: RequestOptions): Promise<OfferResponse>

Paraméterek

options
RequestOptions

Válaszok

Promise<OfferResponse>

readPartitionKeyRanges(FeedOptions)

Lekéri a tároló partíciókulcs-tartományait.

példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const { resources: ranges } = await container.readPartitionKeyRanges().fetchAll();
function readPartitionKeyRanges(feedOptions?: FeedOptions): QueryIterator<PartitionKeyRange>

Paraméterek

feedOptions
FeedOptions

A kérés beállításai.

Válaszok

QueryIterator<PartitionKeyRange>

A partíciókulcs-tartományok iterátora.

replace(ContainerDefinition, RequestOptions)

A tároló definíciójának cseréje

példa

import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const key = "<database account masterkey>";
const client = new CosmosClient({ endpoint, key });

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });

const containerDefinition = {
  id: "Test Container",
  partitionKey: {
    paths: ["/key1"],
  },
  throughput: 1000,
};
const { container } = await database.containers.createIfNotExists(containerDefinition);

containerDefinition.throughput = 400;
const { container: replacedContainer } = await container.replace(containerDefinition);
function replace(body: ContainerDefinition, options?: RequestOptions): Promise<ContainerResponse>

Paraméterek

options
RequestOptions

Válaszok

semanticRerank(string, string[], SemanticRerankOptions)

Megjegyzés

Ez a API bétaverziója; fejlesztői előzetes verzióként szolgál, és a kapott visszajelzések alapján változhat. Ne használja ezt az API-t éles környezetben.

Rangsorolj újra egy dokumentumlistát szemantikai rangsorolással a Cosmos DB Inference Service-en keresztül. Ez a módszer szemantikai újrarangsorolást használ, hogy a megadott dokumentumokat pontozza és átrendezze azok relevanciájuk alapján az adott kontextussal.

A szemantikai újrarangoló kérések külön HTTP pipeline-t használnak a fő Cosmos DB klienstől, és nem használják az alapértelmezett SDK újrapróbálási szabályzatokat.

A funkció használatához a következőket kell tennie:

  1. AAD hitelesítés konfigurálása a aadCredentialsCosmosClientOptions
  2. A következtetés végpontot az in -en enablePreviewFeatures.semanticRerank.inferenceEndpoint keresztül adjuk meg CosmosClientOptions

példa

A lekérdezési eredmények szemantikai újrarangsorolását

import { DefaultAzureCredential } from "@azure/identity";
import { CosmosClient } from "@azure/cosmos";

const endpoint = "https://your-account.documents.azure.com";
const aadCredentials = new DefaultAzureCredential();
const client = new CosmosClient({
  endpoint,
  aadCredentials,
  enablePreviewFeatures: {
    semanticRerank: {
      inferenceEndpoint: "https://your-account.<region>.dbinference.azure.com",
    },
  },
});

const { database } = await client.databases.createIfNotExists({ id: "Test Database" });
const { container } = await database.containers.createIfNotExists({ id: "Test Container" });

const queryResults = ["doc1 JSON", "doc2 JSON", "doc3 JSON"];
const result = await container.semanticRerank(
  "most economical with multiple adjustments",
  queryResults,
  { return_documents: true, top_k: 10, sort: true },
);
// Access the top-ranked document
if (result.rerankScores.length > 0) {
  const topResult = result.rerankScores[0];
  const topScore = topResult.score;
  const topDocument = topResult.document;
  if (topDocument) {
    console.log("Top-ranked document:", topDocument);
  }
  console.log("Top score:", topScore);
}
function semanticRerank(rerankContext: string, documents: string[], options?: SemanticRerankOptions): Promise<SemanticRerankResult>

Paraméterek

rerankContext

string

A kontextus (pl. lekérdezési lánc) a dokumentumok újrarangsorolásához.

documents

string[]

Egy lista a dokumentumokról (JSON stringként), amelyeket át kell rangsorolni.

options
SemanticRerankOptions

Opcionális beállítások szótára az újrarangsorolási kérelmhez. Ismert szolgáltatási lehetőségek:

  • return_documents (boolean) — A válaszban szerepeljenek az átsorolt dokumentumok.
  • top_k (szám) — a legmagasabb rangsorolt dokumentumok maximális száma, amit vissza kell adni.
  • batch_size (szám) — dokumentumfeldolgozáshoz szükséges csomagméret.
  • sort (boolean) — sorolja az eredményeket relevancia pontszám szerint csökkenő sorrendben.
  • document_type ("string" | "json") — a dokumentumok típusa, amelyeket átrangolnak.
  • target_paths(string) — vesszővel elválasztott JSON útvonalak (amikor document_type )."json"
  • abortSignal (AbortSignal) — jel a kérés törlésére. Minden további kulcsot továbbítanak as-is az inferencia szolgáltatásnak.

Válaszok

Az újrarangsorolás eredményei tartalmazzák a pontozott dokumentumokat, késleltetést és token használatot.