Skip to main content
Retrieves detailed information about a specific collection, including its schema and metadata.

Method Signature

collections().get(name: string): Promise<Collection>

Parameters

name
string
required
The name of the collection to retrieve.

Returns

Collection
object
Returns a Collection object containing metadata about the collection.
name
string
Name of the collection
orgId
string
Organization ID that owns the collection
projectId
string
Project ID that contains the collection
schema
Record<string, CollectionFieldSpec>
Schema definition for the collection fields, including data types, required status, and index configurations
region
string
Region where the collection is stored

Examples

Get Collection Information

import { Client } from "topk-js";

const client = new Client({
  apiKey: process.env.TOPK_API_KEY,
  region: "us-east-1"
});

const collection = await client.collections().get("books");

console.log(`Collection: ${collection.name}`);
console.log(`Region: ${collection.region}`);
console.log(`Project: ${collection.projectId}`);

Inspect Collection Schema

import { Client } from "topk-js";

const client = new Client({
  apiKey: process.env.TOPK_API_KEY,
  region: "us-east-1"
});

const collection = await client.collections().get("books");

console.log(`Schema for ${collection.name}:`);
for (const [fieldName, fieldSpec] of Object.entries(collection.schema)) {
  const required = fieldSpec.required ? " (required)" : "";
  const indexed = fieldSpec.index ? " [indexed]" : "";
  console.log(`  ${fieldName}: ${fieldSpec.dataType.type}${required}${indexed}`);
}

Verify Collection Exists

import { Client } from "topk-js";

const client = new Client({
  apiKey: process.env.TOPK_API_KEY,
  region: "us-east-1"
});

async function collectionExists(name) {
  try {
    await client.collections().get(name);
    return true;
  } catch (error) {
    if (error.message.includes("not found")) {
      return false;
    }
    throw error;
  }
}

const exists = await collectionExists("books");
console.log(`Collection exists: ${exists}`);

Check for Vector Index

import { Client } from "topk-js";

const client = new Client({
  apiKey: process.env.TOPK_API_KEY,
  region: "us-east-1"
});

const collection = await client.collections().get("products");

const vectorFields = Object.entries(collection.schema)
  .filter(([_, spec]) => 
    spec.index && spec.index.type === "VectorIndex"
  )
  .map(([name, _]) => name);

console.log(`Vector indexed fields: ${vectorFields.join(", ")}`);
If the collection does not exist, this method will throw an error. Use try-catch (JavaScript) or try-except (Python) to handle this case gracefully.

Build docs developers (and LLMs) love