במדריך למתחילים הזה נסביר איך לענות על שאילתות, לחפש ולאחזר מאמרי עזרה למפתחים באמצעות Developer Knowledge API ו-Google Cloud CLI.
לפני שמתחילים
לפני שמתחילים להשתמש ב-Developer Knowledge API עם ה-CLI של gcloud, צריך לבצע את השלבים הבאים.
התקנה והגדרה של ה-CLI של gcloud
כדי להתקין ולהגדיר את ה-CLI של gcloud:
אם לא התקנתם את ה-CLI של gcloud, התקינו אותו.
מריצים את הפקודה
gcloud components updateכדי לוודא שמותקנת הגרסה העדכנית:gcloud components update
נכנסים לחשבון Google Cloud באמצעות הפקודה
gcloud auth login:gcloud auth login
מגדירים את הפרויקט הפעיל ב-Google Cloud באמצעות הפעלת הפקודה
gcloud config set:gcloud config set project PROJECT_ID
מחליפים את
PROJECT_IDבמזהה הפרויקט ב-Google Cloud.
הפעלת ה-API
כדי להפעיל את Developer Knowledge API:
מפעילים את Developer Knowledge API בפרויקט בענן ב-Google Cloud באמצעות הפקודה
gcloud services enable:gcloud services enable developerknowledge.googleapis.com
כדי להפעיל את ה-API או להשתמש בו, לא צריך תפקידים ספציפיים של ניהול זהויות והרשאות גישה (IAM).
מריצים את הפקודה
gcloud services listכדי לוודא שה-API מופעל בפרויקט: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לפיreferenceIndex. -
references: קטעי התיעוד והמטא-נתונים של המקור, כולל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ו-updateTime. -
id: המזהה של מקטע הטקסט במסמך. -
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: הטקסט המלא של המסמך ב-Markdown. -
contentLengthBytes: הגודל הכולל של תוכן המסמך בבייטים. -
dataSource: הדומיין שבו מתארח המסמך. -
description: סיכום קצר של המסמך. -
name: שם המשאב הייחודי של המסמך. -
title: שם המסמך. -
updateTime: חותמת הזמן של העדכון האחרון של המסמך. -
uri: כתובת ה-URL הציבורית של דף התיעוד. -
view: תצוגת המסמך שהוחזרה (DOCUMENT_VIEW_CONTENT,DOCUMENT_VIEW_BASICאוDOCUMENT_VIEW_FULL).
-
המאמרים הבאים
- איך יוצרים תשובות מתיעוד
- איך מסננים את תוצאות החיפוש, מחלקים אותן לדפים ומציינים תצוגות של מסמכים
- כדי לראות את הרשימה המלאה של המסמכים שכלולים בקורפוס, עיינו במאמרי העזרה של הקורפוס.
- בחומר העזר בנושא
gcloud developer-knowledgeמפורטים כל הפקודות והדגלים הזמינים. - במאמרי העזרה של API בארכיטקטורת REST מפורטים כל המאפיינים של ה-methods ב-API.
- איך מגדירים את שרת Model Context Protocol (MCP) ב-Google Antigravity