บันทึกและชุดข้อมูล

ในคู่มือนี้ คุณจะได้เรียนรู้วิธีดูบันทึกจากการใช้งาน Gemini API ในแดชบอร์ด Google AI Studio เพื่อให้เข้าใจพฤติกรรมของโมเดลและวิธีที่ผู้ใช้อาจโต้ตอบกับแอปพลิเคชันของคุณได้ดียิ่งขึ้น ใช้การบันทึกเพื่อสังเกตการณ์ แก้ไขข้อบกพร่อง และเลือกแชร์ความคิดเห็นเกี่ยวกับการใช้งานกับ Google เพื่อช่วยปรับปรุง Gemini ในกรณีการใช้งานต่างๆ ของนักพัฒนาแอป*

ระบบรองรับการเรียก API ทั้งหมดของ GenerateContent, BatchGenerateContent, StreamGenerateContent และการเรียก API ของ Interactions ยกเว้น Managed Agent ซึ่งรวมถึงการเรียกใช้ผ่านปลายทางความเข้ากันได้กับ OpenAI

กำหนดค่าการบันทึกโปรเจ็กต์

โดยค่าเริ่มต้น ทั้ง Interactions API และ Generate Content API จะจัดเก็บคำขอ (store=true) สำหรับ Interactions API การดำเนินการนี้ยังเปิดใช้ฟีเจอร์การจัดการสถานะฝั่งเซิร์ฟเวอร์ด้วย

ใน Google AI Studio คุณสามารถเปิดหรือปิดใช้พื้นที่เก็บข้อมูลสำหรับแต่ละโปรเจ็กต์ และเปลี่ยนค่ากำหนดเหล่านี้ได้ทุกเมื่อผ่านแผงการตั้งค่าในแดชบอร์ดบันทึก Gemini API คุณสามารถเปิดหรือปิดการบันทึกแยกกันสำหรับ generateContent API และ Interactions API เพื่อเปลี่ยนลักษณะการทำงานของพื้นที่เก็บข้อมูลเริ่มต้นสำหรับโปรเจ็กต์ได้

การบันทึกระดับคำขอ

API ทั้ง 2 รายการจะจัดเก็บคำขอโดยค่าเริ่มต้น (store=true) ดังนี้

  • Interactions API: จัดเก็บคำขอโดยค่าเริ่มต้นเพื่อลดความซับซ้อนในการจัดการสถานะฝั่งเซิร์ฟเวอร์
  • Generate Content API (generateContent, streamGenerateContent และ batchGenerateContent): จัดเก็บคำขอโดยค่าเริ่มต้นสำหรับโปรเจ็กต์ที่สร้างในวันที่ 26 ตุลาคม 2026 เป็นต้นไป โปรเจ็กต์ที่สร้างก่อนวันที่ดังกล่าวจะไม่จัดเก็บคำขอโดยค่าเริ่มต้น (store=false) เว้นแต่จะเปิดใช้การบันทึกใน AI Studio

พร็อพเพอร์ตี้ store ระดับคำขอจะมีความสำคัญเหนือกว่าการตั้งค่าระดับโปรเจ็กต์ การตั้งค่า store ในคำขอ Generate Content API ต้องใช้ google-genai 2.33.0 ขึ้นไปสำหรับ Python, @google/genai 2.31.0 ขึ้นไปสำหรับ JavaScript, google-genai 1.79.0 ขึ้นไปสำหรับ Java และ google.golang.org/genai 1.76.0 ขึ้นไปสำหรับ Go วิธีตั้งค่าพร็อพเพอร์ตี้ store มีดังนี้

GenerateContent API

Python

from google import genai

client = genai.Client()

response = client.models.generate_content(
    model='gemini-3.8-flash',
    contents='Explain quantum entanglement in simple terms.',
    config={'store': True} # Set to False to disable logging of this request
)

print(response.text)

JavaScript

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const response = await client.models.generateContent({
    model: 'gemini-3.8-flash',
    contents: 'Explain quantum entanglement in simple terms.',
    config: {
        store: true // Set to false to disable logging of this request
    }
});

console.log(response.text);

Java

import com.google.genai.Client;
import com.google.genai.types.GenerateContentConfig;
import com.google.genai.types.GenerateContentResponse;

Client client = new Client();

GenerateContentResponse response =
    client.models.generateContent(
        "gemini-3.8-flash",
        "Explain quantum entanglement in simple terms.",
        GenerateContentConfig.builder()
            .store(true) // Set to false to disable logging of this request
            .build());

System.out.println(response.text());

Go

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/genai"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    response, err := client.Models.GenerateContent(
        ctx,
        "gemini-3.8-flash",
        genai.Text("Explain quantum entanglement in simple terms."),
        &genai.GenerateContentConfig{
            Store: genai.Ptr(true), // Set to false to disable logging of this request
        },
    )
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(response.Text())
}

Interactions API

Python

from google import genai

client = genai.Client()

interaction = client.interactions.create(
    model="gemini-3.8-flash",
    input="Explain quantum entanglement in simple terms.",
    store=True # Set to False to disable logging of this request
)

print(interaction.outputs[-1].text)

JavaScript

import { GoogleGenAI } from '@google/genai';

const client = new GoogleGenAI({});

const interaction = await client.interactions.create({
    model: 'gemini-3.8-flash',
    input: 'Explain quantum entanglement in simple terms.',
    store: true // Set to false to disable logging of this request
});

console.log(interaction.outputs[interaction.outputs.length - 1].text);

Java

import com.google.genai.Client;
import com.google.genai.gaos.models.interactions.CreateModelInteraction;
import com.google.genai.gaos.models.interactions.Interaction;
import com.google.genai.gaos.models.interactions.InteractionsInput;
import com.google.genai.gaos.models.interactions.Model;
import com.google.genai.gaos.models.operations.CreateInteractionRequestBody;

Client client = new Client();

CreateModelInteraction params =
    CreateModelInteraction.builder()
        .model(Model.of("gemini-3.8-flash"))
        .input(InteractionsInput.of("Explain quantum entanglement in simple terms."))
        .store(true) // Set to false to disable logging of this request
        .build();

Interaction interaction =
    client.interactions.create(CreateInteractionRequestBody.of(params)).interaction().get();

System.out.println(interaction.outputText().orElse(""));

Go

package main

import (
    "context"
    "fmt"
    "log"

    "google.golang.org/genai"
    "google.golang.org/genai/interactions/models/interactions"
    "google.golang.org/genai/interactions/models/operations"
)

func main() {
    ctx := context.Background()
    client, err := genai.NewClient(ctx, nil)
    if err != nil {
        log.Fatal(err)
    }

    res, err := client.Interactions.Create(ctx, operations.CreateInteractionRequest{
        Body: operations.NewCreateInteractionRequestBody(interactions.CreateModelInteraction{
            Model: interactions.Model("gemini-3.8-flash"),
            Input: interactions.NewInteractionsInput("Explain quantum entanglement in simple terms."),
            Store: genai.Ptr(true), // Set to false to disable logging of this request
        }),
    })
    if err != nil {
        log.Fatal(err)
    }
    if res.Interaction.OutputText != nil {
        fmt.Println(*res.Interaction.OutputText)
    }
}

ดูบันทึกของโปรเจ็กต์ใน AI Studio

  1. ไปที่หน้าบันทึกใน AI Studio
  2. เลือกโปรเจ็กต์จากเมนูแบบเลื่อนลง
  3. บันทึกจะปรากฏในตารางตามลำดับเวลาจากใหม่ไปเก่า (หากมี)
  4. สำหรับโปรเจ็กต์ที่สร้างก่อนวันที่ 26 ตุลาคม 2026 ให้เปิดใช้การบันทึก Generate Content API ในแผงการตั้งค่าก่อนเพื่อดูบันทึกโปรเจ็กต์สำหรับ Generate Content API

คลิกรายการเพื่อดูตัวอย่างเพย์โหลด คุณสามารถตรวจสอบพรอมต์และคำตอบแบบเต็มจาก Gemini รวมถึงบริบทจากเทิร์นก่อนหน้าได้ สำหรับคำขอ Interactions API บันทึกจะมีลิงก์โดยตรงไปยัง previous_interaction_id ด้วย

กำหนดค่าการเก็บรักษาพื้นที่เก็บข้อมูลของโปรเจ็กต์

บันทึกจะหมดอายุและทำเครื่องหมายเพื่อลบหลังจากผ่านกรอบเวลาการเก็บรักษาเริ่มต้น 55 วัน (เว้นแต่จะบันทึกไว้ในชุดข้อมูล ซึ่งจะไม่มีวันหมดอายุ) คุณสามารถกำหนดค่ากรอบเวลาการเก็บรักษาบันทึกของโปรเจ็กต์เป็น 7, 14, 28 หรือสูงสุด 55 วันได้

สร้างและแชร์ชุดข้อมูล

คุณสามารถบันทึกบันทึกไปยังชุดข้อมูลเพื่อจัดระเบียบและส่งออกได้อย่างมีประสิทธิภาพมากขึ้น

  • จากหน้าบันทึก ให้ค้นหาแถบตัวกรองที่ด้านบนเพื่อเลือกพร็อพเพอร์ตี้ที่จะกรอง
  • จากมุมมองตัวกรอง ให้ใช้ช่องทำเครื่องหมายเพื่อเลือกบันทึกทั้งหมดหรือบันทึกแต่ละรายการ
  • คลิกปุ่มสร้างชุดข้อมูลที่ปรากฏที่ด้านบนของรายการ
  • ตั้งชื่อและใส่คำอธิบาย (ไม่บังคับ) ให้กับชุดข้อมูลใหม่
  • คุณจะเห็นชุดข้อมูลที่เพิ่งสร้างขึ้นพร้อมชุดบันทึกที่ดูแลจัดการแล้ว
  • ส่งออกชุดข้อมูลเพื่อการวิเคราะห์เพิ่มเติมเป็นไฟล์ CSV, JSONL หรือไปยัง Google ชีต

ชุดข้อมูลมีประโยชน์สำหรับกรณีการใช้งานที่หลากหลาย

  • ดูแลจัดการชุดคำถามทดสอบ: ขับเคลื่อนการปรับปรุงในอนาคตที่กำหนดเป้าหมายไปยังด้านที่คุณต้องการให้ AI ปรับปรุง
  • ดูแลจัดการชุดตัวอย่าง: เช่น ตัวอย่างจากการใช้งานจริงเพื่อสร้างคำตอบจากโมเดลอื่น หรือคอลเล็กชันเคสที่ผิดปกติสำหรับการตรวจสอบตามปกติก่อนการทำให้ใช้งานได้
  • ชุดการประเมิน: ชุดที่เป็นตัวแทนของการใช้งานจริงในความสามารถที่สำคัญ เพื่อเปรียบเทียบกับโมเดลอื่นๆ หรือการทำซ้ำคำสั่งของระบบ

คุณสามารถมีส่วนร่วมในการวิจัยและพัฒนา Gemini ได้โดยเลือกแชร์ชุดข้อมูลกับ Google เพื่อเป็นตัวอย่างสาธิต

ข้อจำกัด

ปัจจุบันระบบยังไม่รองรับการบันทึกสำหรับรายการต่อไปนี้

  • โมเดล Imagen และ Veo
  • โมเดลการฝังของ Gemini
  • โมเดล Gemini Robotics
  • ข้อมูลที่ป้อนซึ่งมีวิดีโอ, GIF หรือ PDF
  • Agent เวอร์ชันตัวอย่างแบบสาธารณะใน Gemini API

ขั้นตอนถัดไป

  • สร้างต้นแบบด้วยประวัติเซสชัน: ใช้ AI Studio Build เพื่อเขียนโค้ดแอปแบบ Vibe Coding และเพิ่มคีย์ API เพื่อเปิดใช้ประวัติบันทึก Gemini API สำหรับฟีเจอร์ AI
  • เรียกใช้บันทึกซ้ำด้วย Gemini Batch API: ใช้ชุดข้อมูลสำหรับการสุ่มตัวอย่างคำตอบและการประเมินโมเดลหรือตรรกะของแอปพลิเคชันโดยเรียกใช้บันทึกซ้ำด้วย Gemini Batch API