Package google.developers.knowledge.v1

索引

DeveloperKnowledge

Developer Knowledge API 可讓您透過程式輔助方式存取 Google 的公開開發人員說明文件,將這個知識庫整合至自己的應用程式和工作流程。

這個 API 是 Google 開發人員說明文件的標準來源,可讓機器讀取。

常見的使用案例是先使用 DeveloperKnowledge.SearchDocumentChunks 根據查詢找出相關文件區塊,然後使用 DeveloperKnowledge.GetDocument 或 DeveloperKnowledge.BatchGetDocuments 搭配文件資源名稱 (例如 DocumentChunk.parent 或 documents/{uri_without_scheme}),擷取熱門結果的完整內容。

所有文件內容均以 Markdown 格式提供。

AnswerQuery

rpc AnswerQuery(AnswerQueryRequest) returns (AnswerQueryResponse)

使用有依據的生成內容回答查詢。

授權範圍

需要下列其中一種 OAuth 範圍:

  • https://www.googleapis.com/auth/devprofiles.full_control
  • https://www.googleapis.com/auth/developerprofiles.readonly
  • https://www.googleapis.com/auth/cloud-platform

詳情請參閱OAuth 2.0 Overview。

BatchGetDocuments

rpc BatchGetDocuments(BatchGetDocumentsRequest) returns (BatchGetDocumentsResponse)

擷取多份文件,每份文件都包含完整的 Markdown 內容。

授權範圍

需要下列其中一種 OAuth 範圍:

  • https://www.googleapis.com/auth/devprofiles.full_control
  • https://www.googleapis.com/auth/developerprofiles.readonly
  • https://www.googleapis.com/auth/cloud-platform

詳情請參閱OAuth 2.0 Overview。

GetDocument

rpc GetDocument(GetDocumentRequest) returns (Document)

擷取單一文件及其完整的 Markdown 內容。

授權範圍

需要下列其中一種 OAuth 範圍:

  • https://www.googleapis.com/auth/devprofiles.full_control
  • https://www.googleapis.com/auth/developerprofiles.readonly
  • https://www.googleapis.com/auth/cloud-platform

詳情請參閱OAuth 2.0 Overview。

SearchDocumentChunks

rpc SearchDocumentChunks(SearchDocumentChunksRequest) returns (SearchDocumentChunksResponse)

在 Google 開發人員說明文件中搜尋開發人員知識。根據使用者的查詢傳回 DocumentChunk。同一個 Document 可能會有多個區塊。如要擷取完整文件,請使用 DeveloperKnowledge.GetDocument 或 DeveloperKnowledge.BatchGetDocuments,並搭配 SearchDocumentChunksResponse.results 中傳回的 DocumentChunk.parent。

授權範圍

需要下列其中一種 OAuth 範圍:

  • https://www.googleapis.com/auth/devprofiles.full_control
  • https://www.googleapis.com/auth/developerprofiles.readonly
  • https://www.googleapis.com/auth/cloud-platform

詳情請參閱OAuth 2.0 Overview。

解答

查詢的答案。

欄位
answer_text

string

包含答案的文字。

citations[]

AnswerCitation

僅供輸出。包含答案的引用內容。

references[]

AnswerReference

僅供輸出。包含答案的參考資料。

AnswerCitation

區段的引用資訊。

欄位
start_index

int32

僅供輸出。表示區隔的開頭,以位元組 (UTF-8 Unicode) 為單位,包含在內。如果有多位元組字元 (例如非 ASCII 字元),索引測量值會大於字串長度。

end_index

int32

僅供輸出。表示區隔的結尾,以位元組 (UTF-8 Unicode) 為單位,不含該值。如果有多位元組字元 (例如非 ASCII 字元),索引測量值會大於字串長度。

sources[]

CitationSource

僅供輸出。包含歸因區隔的引用來源。

AnswerReference

代表來源的參照。

欄位
聯集欄位 content。包含參考資料的內容。content 只能是下列其中一項:
document_reference

DocumentReference

僅供輸出。參考文件。

CitationSource

引用來源。

欄位
reference_index

int32

僅供輸出。包含 references 重複欄位中 Answer.AnswerReference 的索引。

DocumentReference

代表文件的參照。

欄位
document_chunk

DocumentChunk

僅供輸出。包含文件區塊。未設定「document_chunk.id」欄位,因此會留空。

AnswerQueryRequest

DeveloperKnowledge.AnswerQuery 的要求訊息。

欄位
query

string

必填。要回答的查詢。

filter

string

(選用步驟) 對用於建立答案的搜尋結果套用嚴格篩選器。運算式支援 https://google.aip.dev/160 所述的部分語法。

支援篩選的欄位:

  • content_length_bytes (INTEGER):Document.content 欄位的長度 (以位元組為單位)。
  • data_source (STRING):文件來源,例如 docs.cloud.google.com。如要查看語料庫中的完整資料來源清單,請前往 https://developers.google.com/knowledge/reference/corpus-reference。
  • update_time (TIMESTAMP):文件上次進行實質更新的時間戳記。有意義的更新是指會變更文件 Markdown 內容或中繼資料的更新。
  • uri (STRING):文件 URI,例如 https://docs.cloud.google.com/bigquery/docs/tables。

INTEGER 欄位支援 =、<、<=、> 和 >= 運算子。

STRING 欄位支援 = (等於) 和 != (不等於) 運算子,可對整個字串進行完全比對。不支援部分比對、前置字元比對和規則運算式比對。

TIMESTAMP 欄位支援 =、<、<=、> 和 >= 運算子。時間戳記必須採用 RFC-3339 格式,例如 "2025-01-01T00:00:00Z"。

您可以使用 AND、OR 和 NOT (或 -) 邏輯運算子合併運算式。OR 的優先順序高於 AND。使用括號明確分組優先順序。

範例:

  • 依Document.content_length_bytes篩選:content_length_bytes < 50000
  • data_source = "docs.cloud.google.com" OR data_source = "firebase.google.com"
  • data_source != "firebase.google.com"
  • update_time < "2024-01-01T00:00:00Z"
  • update_time >= "2025-01-22T00:00:00Z" AND (data_source = "developer.chrome.com" OR data_source = "web.dev")
  • uri = "https://docs.cloud.google.com/release-notes"

filter 字串不得超過 500 個字元,否則會導致 INVALID_ARGUMENT 錯誤。

AnswerQueryResponse

DeveloperKnowledge.AnswerQuery 的回應訊息。

欄位
answer

Answer

查詢的答案。

BatchGetDocumentsRequest

DeveloperKnowledge.BatchGetDocuments 的要求訊息。

欄位
names[]

string

必填。指定要擷取的文件名稱。一次最多可擷取 20 份文件。文件傳回的順序與要求中的 names 相同。

格式:documents/{uri_without_scheme} 範例:documents/docs.cloud.google.com/storage/docs/creating-buckets

每個名稱不得超過 500 個半形字元,否則會導致 INVALID_ARGUMENT 錯誤。

view

DocumentView

(選用步驟) 指定文件的 DocumentView。如未指定,DeveloperKnowledge.BatchGetDocuments 預設為 DOCUMENT_VIEW_CONTENT。

BatchGetDocumentsResponse

DeveloperKnowledge.BatchGetDocuments 的回應訊息。

欄位
documents[]

Document

包含要求的文件。

文件

文件代表開發人員知識語料庫中的說明文件頁面,例如 https://docs.cloud.google.com/storage/docs/creating-buckets。

欄位
name

string

ID。包含文件的資源名稱。格式:documents/{uri_without_scheme} 範例:documents/docs.cloud.google.com/storage/docs/creating-buckets

uri

string

僅供輸出。提供內容的 URI,例如 https://docs.cloud.google.com/storage/docs/creating-buckets。

content

string

僅供輸出。包含文件的完整內容,格式為 Markdown。

description

string

僅供輸出。提供文件說明。

data_source

string

僅供輸出。指定文件的資料來源。資料來源範例:firebase.google.com

title

string

僅供輸出。提供文件標題。

update_time

Timestamp

僅供輸出。代表文件內容或中繼資料上次更新的時間戳記。

view

DocumentView

僅供輸出。指定文件的 DocumentView。

content_length_bytes

int32

僅供輸出。content 欄位的長度 (以位元組為單位)。

DocumentChunk

DocumentChunk 代表 DeveloperKnowledge 語料庫中 Document 的一部分內容。如要擷取整份文件內容,請將 parent 傳遞至 DeveloperKnowledge.GetDocument 或 DeveloperKnowledge.BatchGetDocuments。

欄位
parent

string

僅供輸出。包含這個 chunk 來源文件的資源名稱。格式:documents/{uri_without_scheme} 範例:documents/docs.cloud.google.com/storage/docs/creating-buckets

id

string

僅供輸出。指定這項區塊在文件中的 ID。區塊 ID 在文件中不得重複,但不同文件可以有相同的區塊 ID。區塊 ID 並非固定不變,可能會隨著時間而改變。

content

string

僅供輸出。包含文件區塊的內容。

document

Document

僅供輸出。代表這個區塊來源 Document 的中繼資料。這則 Document 訊息的 DocumentView 將設為 DOCUMENT_VIEW_BASIC。為方便起見,我們在此加入這個欄位,這樣一來,如果用戶端只需要中繼資料欄位,就不需要呼叫 DeveloperKnowledge.GetDocument 或 DeveloperKnowledge.BatchGetDocuments。否則,用戶端應使用 DeveloperKnowledge.GetDocument 或 DeveloperKnowledge.BatchGetDocuments 擷取完整文件內容。

relevance_score

double

僅供輸出。代表區塊與搜尋查詢的關聯性分數。分數越高,表示區塊關聯性越高。分數範圍為 [0.0, 1.0]。

DocumentView

指定要納入 Document 的哪些欄位。

列舉
DOCUMENT_VIEW_UNSPECIFIED 預設 / 未設定的值。如未指定 DocumentView,請查看各個 API 方法的預設值。
DOCUMENT_VIEW_BASIC

僅包含基本中繼資料欄位:

  • name
  • uri
  • data_source
  • title
  • description
  • update_time
  • view
  • content_length_bytes

這是 DeveloperKnowledge.SearchDocumentChunks 的預設檢視畫面。

DOCUMENT_VIEW_FULL 包含所有 Document 欄位。
DOCUMENT_VIEW_CONTENT

包含 DOCUMENT_VIEW_BASIC 欄位和 content 欄位。

這是 DeveloperKnowledge.GetDocument 和 DeveloperKnowledge.BatchGetDocuments 的預設檢視畫面。

GetDocumentRequest

DeveloperKnowledge.GetDocument 的要求訊息。

欄位
name

string

必填。指定要擷取的文件名稱。格式:documents/{uri_without_scheme} 範例:documents/docs.cloud.google.com/storage/docs/creating-buckets

名稱長度不得超過 500 個半形字元,否則會導致 INVALID_ARGUMENT 錯誤。

view

DocumentView

(選用步驟) 指定文件的 DocumentView。如未指定,DeveloperKnowledge.GetDocument 預設為 DOCUMENT_VIEW_CONTENT。

SearchDocumentChunksRequest

DeveloperKnowledge.SearchDocumentChunks 的要求訊息。

欄位
query

string

必填。提供使用者輸入的原始查詢字串,例如「如何建立 Cloud Storage bucket?」。查詢長度不得超過 500 個半形字元,否則會導致 INVALID_ARGUMENT 錯誤。

page_size

int32

(選用步驟) 指定要傳回的結果數上限。服務傳回的產品數量可能會少於這個值。

如未指定,最多會傳回 5 筆結果。

許可的最大值為 100;超出的數值將一律指定為 100。

page_token

string

(選用步驟) 包含接收自前一個 SearchDocumentChunks 呼叫的網頁權杖。提供此項目即可擷取後續網頁。

filter

string

(選用步驟) 對搜尋結果套用嚴格篩選器。運算式支援 https://google.aip.dev/160 所述的部分語法。

雖然 SearchDocumentChunks 會傳回 DocumentChunk,但篩選器會套用至 DocumentChunk.document 欄位。

支援篩選的欄位:

  • content_length_bytes (INTEGER):Document.content 欄位的長度 (以位元組為單位)。
  • data_source (STRING):文件來源,例如 docs.cloud.google.com。如要查看語料庫中的完整資料來源清單,請前往 https://developers.google.com/knowledge/reference/corpus-reference。
  • update_time (TIMESTAMP):文件上次進行實質更新的時間戳記。有意義的更新是指會變更文件 Markdown 內容或中繼資料的更新。
  • uri (STRING):文件 URI,例如 https://docs.cloud.google.com/bigquery/docs/tables。

INTEGER 欄位支援 =、<、<=、> 和 >= 運算子。

STRING 欄位支援 = (等於) 和 != (不等於) 運算子,可對整個字串進行完全比對。不支援部分比對、前置字元比對和規則運算式比對。

TIMESTAMP 欄位支援 =、<、<=、> 和 >= 運算子。時間戳記必須採用 RFC-3339 格式,例如 "2025-01-01T00:00:00Z"。

注意:欄位名稱必須採用 snake_case (例如 data_source)。篩選運算式右側的值必須是以雙引號括住的字串常值 (例如 "docs.cloud.google.com")。

您可以使用 AND、OR 和 NOT (或 -) 邏輯運算子合併運算式。OR 的優先順序高於 AND。使用括號明確分組優先順序。

範例:

  • 依Document.content_length_bytes篩選:content_length_bytes < 50000
  • data_source = "docs.cloud.google.com" OR data_source = "firebase.google.com"
  • data_source != "firebase.google.com"
  • update_time < "2024-01-01T00:00:00Z"
  • update_time >= "2025-01-22T00:00:00Z" AND (data_source = "developer.chrome.com" OR data_source = "web.dev")
  • uri = "https://docs.cloud.google.com/release-notes"

filter 字串不得超過 500 個字元,否則會導致 INVALID_ARGUMENT 錯誤。

SearchDocumentChunksResponse

DeveloperKnowledge.SearchDocumentChunks 的回應訊息。

欄位
results[]

DocumentChunk

包含指定查詢的搜尋結果。這份清單中的每個 DocumentChunk 都包含與搜尋查詢相關的內容片段。將每項結果的 DocumentChunk.parent 欄位與 DeveloperKnowledge.GetDocument 或 DeveloperKnowledge.BatchGetDocuments 搭配使用,即可擷取完整文件內容。

next_page_token

string

提供可做為 page_token 傳送的權杖,用於擷取後續網頁。如果省略這個欄位,就不會有後續頁面。