คู่มือเริ่มใช้งานฉบับย่อนี้จะแสดงวิธีตอบคำถาม รวมถึงค้นหาและดึงข้อมูลเอกสารประกอบสำหรับนักพัฒนาซอฟต์แวร์ด้วย Developer Knowledge API โดยใช้ Google Cloud CLI
ก่อนเริ่มต้น
ก่อนเริ่มใช้ Developer Knowledge API กับ gcloud CLI ให้ทำตามขั้นตอนต่อไปนี้
ติดตั้งและกำหนดค่า gcloud CLI
หากต้องการติดตั้งและกำหนดค่า gcloud CLI ให้ทำตามขั้นตอนต่อไปนี้
หากยังไม่ได้ติดตั้ง gcloud CLI ให้ติดตั้ง gcloud CLI
เรียกใช้คำสั่ง
gcloud components updateเพื่อตรวจสอบว่าคุณมีเวอร์ชันล่าสุดgcloud components update
ลงชื่อเข้าใช้บัญชี Google Cloud โดยเรียกใช้คำสั่ง
gcloud auth loginดังนี้gcloud auth login
ตั้งค่าโปรเจ็กต์ที่อยู่ในระบบคลาวด์ Google ที่ใช้งานอยู่โดยเรียกใช้คำสั่ง
gcloud config setดังนี้gcloud config set project PROJECT_ID
แทนที่
PROJECT_IDด้วยรหัสโปรเจ็กต์ที่อยู่ในระบบคลาวด์ของ Google
เปิดใช้ API
หากต้องการเปิดใช้ Developer Knowledge API ให้ทำตามขั้นตอนต่อไปนี้
เปิดใช้ Developer Knowledge API ในโปรเจ็กต์ที่อยู่ในระบบคลาวด์ Google โดยเรียกใช้คำสั่ง
gcloud services enableดังนี้gcloud services enable developerknowledge.googleapis.com
คุณไม่จำเป็นต้องมีบทบาท Identity and Access Management (IAM) ที่เฉพาะเจาะจงเพื่อเปิดใช้หรือใช้ API
ตรวจสอบว่าได้เปิดใช้ API สำหรับโปรเจ็กต์แล้วโดยเรียกใช้คำสั่ง
gcloud services listดังนี้gcloud services list --enabled \ --filter="name:developerknowledge.googleapis.com"เอาต์พุตจะแสดงชื่อและชื่อ API ดังนี้
NAME TITLE developerknowledge.googleapis.com Developer Knowledge API
สร้างคำตอบจากเอกสารประกอบ
คำสั่ง gcloud developer-knowledge answer-query ช่วยให้คุณถามคำถามเกี่ยวกับผลิตภัณฑ์ของ Google และรับคำตอบที่ตรงไปตรงมาและเป็นภาษาธรรมชาติได้ คำสั่งนี้จะดึงข้อมูลจากแหล่งเอกสารอย่างเป็นทางการและระบุการอ้างอิงไปยังหน้าที่อ้างอิง
หากต้องการถามคำถามและสร้างคำตอบ ให้ทำตามขั้นตอนต่อไปนี้
เรียกใช้คำสั่งต่อไปนี้เพื่อถามวิธีสร้างที่เก็บข้อมูล Cloud Storage
gcloud developer-knowledge answer-query \ --query="How do I create a Cloud Storage bucket?"ยืนยันว่าคำสั่งแสดงคำตอบที่สร้างขึ้นและการอ้างอิงแหล่งที่มาในรูปแบบ YAML ดังนี้
answer: answerText: |- To create a Cloud Storage bucket, you can use the Google Cloud console, the gcloud CLI (`gcloud storage buckets create`), client libraries, or the REST API... citations: - endIndex: 158 sources: - referenceIndex: 0 startIndex: 0 references: - documentReference: documentChunk: content: |- This document shows you how to create a Cloud Storage [bucket](https://docs.cloud.google.com/storage/docs/buckets)... document: dataSource: docs.cloud.google.com name: documents/docs.cloud.google.com/storage/docs/creating-buckets title: Create a bucket uri: https://docs.cloud.google.com/storage/docs/creating-buckets parent: documents/docs.cloud.google.com/storage/docs/creating-bucketsออบเจ็กต์
answerในเอาต์พุตประกอบด้วยฟิลด์ต่อไปนี้answerText: คำตอบที่สร้างขึ้นด้วยภาษาธรรมชาติสำหรับคำถามของคุณcitations: ช่วงออฟเซ็ตไบต์startIndexและendIndexในanswerTextที่แมปกับรายการที่รองรับในreferencesตามreferenceIndexreferences: ส่วนย่อยของเอกสารต้นฉบับและข้อมูลเมตา รวมถึงdocumentและparentที่ใช้สร้างคำตอบ
ค้นหาข้อมูลที่แยกย่อยจากเอกสาร
หากต้องการค้นหาข้อความที่ตัดตอนมาที่เฉพาะเจาะจงในเอกสารประกอบสำหรับนักพัฒนาซอฟต์แวร์ของ Google แทนคำตอบที่สร้างขึ้น ให้ใช้คำสั่ง gcloud developer-knowledge documents search-chunks
คำสั่งนี้จะสแกนคลังเอกสารและแสดงผลกลุ่มเนื้อหาที่ตรงกันพร้อมกับชื่อทรัพยากรของเอกสารหลัก
หากต้องการค้นหาข้อมูลที่แยกย่อยจากเอกสาร ให้ทำตามขั้นตอนต่อไปนี้
เรียกใช้คำสั่งต่อไปนี้เพื่อค้นหาเอกสารประกอบเกี่ยวกับการสร้างบักเก็ต Cloud Storage
gcloud developer-knowledge documents search-chunks \ --query="How do I create a Cloud Storage bucket?"ยืนยันว่าคำสั่งแสดงรายการส่วนของเอกสารที่ตรงกันในรูปแบบ YAML ดังนี้
--- content: |- This document shows you how to create a Cloud Storage [bucket](https://docs.cloud.google.com/storage/docs/buckets). If not otherwise specified in your request, buckets are created in the [US multi-region](https://docs.cloud.google.com/storage/docs/locations)... document: contentLengthBytes: 31842 dataSource: docs.cloud.google.com description: World-wide storage and retrieval of data in Google Cloud. name: documents/docs.cloud.google.com/storage/docs/creating-buckets title: Create a bucket updateTime: '2026-09-10T20:05:41Z' uri: https://docs.cloud.google.com/storage/docs/creating-buckets view: DOCUMENT_VIEW_BASIC id: c1 parent: documents/docs.cloud.google.com/storage/docs/creating-buckets relevanceScore: 0.856608ข้อมูลแต่ละส่วนในเอาต์พุตประกอบด้วยฟิลด์ต่อไปนี้
content: ตัวอย่างข้อความที่ตรงกันจากเอกสารประกอบdocument: ข้อมูลเมตาเกี่ยวกับเอกสารแหล่งที่มา ซึ่งรวมถึงtitle,description,uri,dataSourceและupdateTimeid: ตัวระบุของกลุ่มข้อมูลภายในเอกสารparent: ชื่อทรัพยากรของเอกสารหลัก คุณสามารถส่งค่านี้ไปยังคำสั่งdescribeเพื่อดึงข้อมูลเอกสารฉบับเต็มได้relevanceScore: คะแนนความเกี่ยวข้องของกลุ่มข้อมูลกับคำค้นหา
เรียกดูเอกสาร
หลังจากพบส่วนของเอกสารที่เกี่ยวข้องแล้ว ให้ใช้ช่อง parent จากผลการค้นหาเหล่านั้นเพื่อดึงเนื้อหา Markdown ที่สมบูรณ์ของเอกสาร
เรียกใช้คำสั่ง gcloud developer-knowledge documents describe พร้อมชื่อทรัพยากรของเอกสาร ตัวอย่างเช่น หากต้องการเรียกดูเอกสารเกี่ยวกับการสร้างที่เก็บข้อมูล Cloud Storage ให้ทำตามขั้นตอนต่อไปนี้
เรียกใช้คำสั่งต่อไปนี้
gcloud developer-knowledge documents describe \ documents/docs.cloud.google.com/storage/docs/creating-buckets
ยืนยันว่าคำสั่งแสดงผลข้อมูลเมตาและเนื้อหา Markdown ทั้งหมดของเอกสาร
content: | This document shows you how to create a Cloud Storage [bucket](https://docs.cloud.google.com/storage/docs/buckets). If not otherwise specified in your request, buckets are created in the [`US` multi-region](https://docs.cloud.google.com/storage/docs/locations) with a default storage class of [Standard storage](https://docs.cloud.google.com/storage/docs/storage-classes) and have a seven-day [soft delete](https://docs.cloud.google.com/storage/docs/soft-delete) retention duration... contentLengthBytes: 31842 dataSource: docs.cloud.google.com description: World-wide storage and retrieval of data in Google Cloud. name: documents/docs.cloud.google.com/storage/docs/creating-buckets title: Create a bucket updateTime: '2026-09-10T20:05:41Z' uri: https://docs.cloud.google.com/storage/docs/creating-buckets view: DOCUMENT_VIEW_CONTENTเอาต์พุตประกอบด้วยฟิลด์ต่อไปนี้
content: ข้อความมาร์กดาวน์แบบเต็มของเอกสารcontentLengthBytes: ขนาดรวมของเนื้อหาเอกสารในหน่วยไบต์dataSource: โดเมนเอกสารประกอบที่โฮสต์เอกสารdescription: สรุปสั้นๆ ของเอกสารname: ชื่อทรัพยากรที่ไม่ซ้ำกันของเอกสารtitle: ชื่อเอกสารupdateTime: การประทับเวลาเมื่อมีการอัปเดตเอกสารครั้งล่าสุดuri: URL สาธารณะของหน้าเอกสารประกอบview: มุมมองเอกสารที่แสดงผล (DOCUMENT_VIEW_CONTENT,DOCUMENT_VIEW_BASICหรือDOCUMENT_VIEW_FULL)
ขั้นตอนถัดไป
- ดูวิธีสร้างคำตอบจากเอกสารประกอบ
- ดูวิธีกรองผลการค้นหา แบ่งหน้า และระบุมุมมองเอกสาร
- สำรวจข้อมูลอ้างอิงของคลังข้อมูลเพื่อดูรายการเอกสารประกอบทั้งหมดที่รวมอยู่
- ดูรายละเอียดเกี่ยวกับคำสั่งและแฟล็กทั้งหมดที่มีได้ในข้อมูลอ้างอิง
gcloud developer-knowledge - ดูข้อกำหนดทั้งหมดสำหรับเมธอด API ได้ที่เอกสารอ้างอิง REST API
- ดูวิธีตั้งค่าเซิร์ฟเวอร์ Model Context Protocol (MCP) ใน Google Antigravity