Skip to main content
Returns a list of all collections in the current project, including their schemas and metadata.

Method Signature

collections().list(): Promise<Array<Collection>>

Parameters

This method does not accept any parameters.

Returns

Collections
Array<Collection>
Returns an array of Collection objects, each containing metadata about a 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
region
string
Region where the collection is stored

Examples

List All Collections

import { Client } from "topk-js";

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

const collections = await client.collections().list();

console.log(`Found ${collections.length} collections:`);
collections.forEach(collection => {
  console.log(`- ${collection.name} (${collection.region})`);
});

Inspect Collection Schemas

import { Client } from "topk-js";

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

const collections = await client.collections().list();

for (const collection of collections) {
  console.log(`\nCollection: ${collection.name}`);
  console.log('Schema:');
  
  for (const [fieldName, fieldSpec] of Object.entries(collection.schema)) {
    console.log(`  ${fieldName}: ${fieldSpec.dataType.type}`);
  }
}

Filter Collections by Name Pattern

import { Client } from "topk-js";

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

const collections = await client.collections().list();
const productCollections = collections.filter(c => 
  c.name.startsWith("product_")
);

console.log(`Found ${productCollections.length} product collections`);
The list operation returns all collections in your project. If you have many collections, consider caching this result if you need to access it frequently.