Returns a list of all collections in the current project, including their schemas and metadata.
Method Signature
collections().list(): Promise<Array<Collection>>
collections().list() -> list[Collection]
Parameters
This method does not accept any parameters.
Returns
Returns an array of Collection objects, each containing metadata about a collection.Organization ID that owns the collection
Project ID that contains the collection
schema
Record<string, CollectionFieldSpec>
Schema definition for the collection fields
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})`);
});
from topk_sdk import Client
import os
client = Client(
api_key=os.environ["TOPK_API_KEY"],
region="us-east-1"
)
collections = client.collections().list()
print(f"Found {len(collections)} collections:")
for collection in collections:
print(f"- {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}`);
}
}
from topk_sdk import Client
import os
client = Client(
api_key=os.environ["TOPK_API_KEY"],
region="us-east-1"
)
collections = client.collections().list()
for collection in collections:
print(f"\nCollection: {collection.name}")
print("Schema:")
for field_name, field_spec in collection.schema.items():
print(f" {field_name}: {field_spec}")
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`);
from topk_sdk import Client
import os
client = Client(
api_key=os.environ["TOPK_API_KEY"],
region="us-east-1"
)
collections = client.collections().list()
product_collections = [
c for c in collections if c.name.startswith("product_")
]
print(f"Found {len(product_collections)} 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.