يوضّح لك دليل البدء السريع هذا كيفية الإجابة عن طلبات البحث والبحث عن مستندات المطوّرين واستردادها باستخدام Developer Knowledge API من خلال Google Cloud CLI.
قبل البدء
قبل البدء في استخدام Developer Knowledge API مع gcloud CLI، أكمِل الخطوات التالية.
تثبيت gcloud CLI وضبطه
لتثبيت gcloud CLI وضبطه، أكمِل الخطوات التالية:
إذا لم تكن قد ثبّتّ gcloud CLI، عليك تثبيته.
شغِّل الأمر
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.
تفعيل واجهة برمجة التطبيقات
لتفعيل واجهة Developer Knowledge API، أكمِل الخطوات التالية:
فعِّل Developer Knowledge API في مشروعك على Google Cloud من خلال تشغيل الأمر
gcloud services enable:gcloud services enable developerknowledge.googleapis.com
لا تحتاج إلى أدوار محدّدة في "إدارة الهوية وإمكانية الوصول" (IAM) لتفعيل واجهة برمجة التطبيقات أو استخدامها.
تأكَّد من تفعيل واجهة برمجة التطبيقات لمشروعك من خلال تنفيذ الأمر
gcloud services list:gcloud services list --enabled \ --filter="name:developerknowledge.googleapis.com"تعرض النتيجة اسم واجهة برمجة التطبيقات وعنوانها:
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للحصول على تفاصيل حول جميع الأوامر والعلامات المتاحة. - راجِع مرجع REST API للحصول على المواصفات الكاملة لطُرق واجهة برمجة التطبيقات.
- كيفية إعداد خادم "بروتوكول سياق النموذج" (MCP) في Google Antigravity