メインコンテンツにスキップ

CorporaApp

This is a Google Apps Script library for managing the corpora of Gemini API.

AI Summary

CorporaApp

A Google Apps Script wrapper library for effortless management of Gemini API corpora

Target Users

Intermediate-to-advanced Google Apps Script developers who are adding Gemini semantic search to internal tools or automation scripts

Problems Solved

Calling Gemini corpus endpoints directly from Apps Script requires verbose HTTP calls and scope handling, making the workflow cumbersome

Tags

Main Features

1
One-liner access to core endpoints

Exposes 15+ methods such as createCorpus and searchQueryFromCorpus, hiding HTTP request/headers so developers call the API with a single line

2
Full coverage: corpus, document, chunk and permission APIs

Covers create, list, update, delete, search and permission operations for all Gemini v1beta resources

3
Works with custom access tokens (e.g., service accounts)

setAccessToken allows injection of externally obtained OAuth tokens, enabling backend or service-account based executions

4
Apps Script autocomplete for safer coding

Return objects are designed so that V8 editor autocomplete works, reducing property-name mistakes

5
Minimal additional OAuth scopes

Only two extra scopes are required—external_request and generative-language.retriever—keeping project configuration simple

Usage Examples

Minimal example: list all corpora

/**
 * Prerequisites:
 * 1. Add the library using project key 1XrAybct1KUwGcFrEZ9BOd5sa0SoHeQwGhOWkDOHki9lDFAX9OHlO03y_
 * 2. Enable the Generative Language API in Cloud Console
 */
function listCorpora() {
  // Fetch an array of existing corpora
  const corpora = CorporaApp.getCorpora();
  // Output to Apps Script logger
  Logger.log(corpora);
}

Run the function and you should see an array of corpus objects in the execution log, proving the library is installed and authenticated correctly.