ข้อมูลเบื้องต้นนี้แสดงวิธีตอบคำค้นหา รวมถึงค้นหาและดึงข้อมูล เอกสารประกอบสำหรับนักพัฒนาซอฟต์แวร์ด้วย 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 Cloud
เปิดใช้ API
หากต้องการเปิดใช้ Developer Knowledge API ให้ทำตามขั้นตอนต่อไปนี้
เปิดใช้ Developer Knowledge API ในโปรเจ็กต์ที่อยู่ในระบบคลาวด์ Google โดยเรียกใช้คำสั่ง
gcloud services enablegcloud 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 และรับคำตอบเป็นภาษาง่ายๆ ได้โดยตรง
คำสั่งนี้จะดึงข้อมูลจากแหล่งข้อมูลเอกสารอย่างเป็นทางการและแสดงการอ้างอิงไปยังหน้าเว็บที่อ้างอิง
หากต้องการถามคำถามและสร้างคำตอบ ให้ทำตามขั้นตอนต่อไปนี้
เรียกใช้คำสั่งต่อไปนี้เพื่อถามวิธีสร้าง Bucket ของ 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ที่ใช้สร้างคำตอบ
ค้นหา Chunk ของเอกสาร
หากต้องการค้นหาข้อความที่เฉพาะเจาะจงในเอกสารประกอบสำหรับนักพัฒนาซอฟต์แวร์ของ 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 จากผลการค้นหาเหล่านั้น
เพื่อดึงเนื้อหามาร์กดาวน์ทั้งหมดของเอกสาร
เรียกใช้คำสั่ง gcloud developer-knowledge documents describe
พร้อมชื่อทรัพยากรของเอกสาร เช่น หากต้องการดึงข้อมูลเอกสารเกี่ยวกับการสร้าง Bucket ใน Cloud Storage ให้ทำตามขั้นตอนต่อไปนี้
เรียกใช้คำสั่งต่อไปนี้
gcloud developer-knowledge documents describe \ documents/docs.cloud.google.com/storage/docs/creating-buckets
ยืนยันว่าคำสั่งจะแสดงข้อมูลเมตาและเนื้อหามาร์กดาวน์ทั้งหมดของ เอกสาร
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)
ขั้นตอนถัดไป
- ดูวิธีสร้างคำตอบจากเอกสารประกอบ
- ดูวิธีกรองผลการค้นหา แบ่งหน้า และระบุมุมมองเอกสาร
- ดูการอ้างอิงคลังข้อมูลเพื่อดูรายการเอกสารทั้งหมดที่รวมไว้
- ดูรายละเอียดเกี่ยวกับคำสั่งและ Flag ทั้งหมดที่มีได้ใน
gcloud developer-knowledgeอ้างอิง - ดูข้อมูลจำเพาะทั้งหมดของเมธอด API ได้ที่ข้อมูลอ้างอิง REST API
- ดูวิธีตั้งค่าเซิร์ฟเวอร์ Model Context Protocol (MCP) ใน Google Antigravity