MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

discoveryengine/search.js:18–93  ·  view source on GitHub ↗
(
  projectId,
  location,
  collectionId,
  dataStoreId,
  servingConfigId,
  searchQuery
)

Source from the content-addressed store, hash-verified

16'use strict';
17
18async function main(
19 projectId,
20 location,
21 collectionId,
22 dataStoreId,
23 servingConfigId,
24 searchQuery
25) {
26 // [START genappbuilder_search]
27 /**
28 * TODO(developer): Uncomment these variables before running the sample.
29 */
30 // const projectId = 'YOUR_PROJECT_ID';
31 // const location = 'YOUR_LOCATION'; // Options: 'global', 'us', 'eu'
32 // const collectionId = 'default_collection'; // Options: 'default_collection'
33 // const dataStoreId = 'YOUR_DATA_STORE_ID' // Create in Cloud Console
34 // const servingConfigId = 'default_config'; // Options: 'default_config'
35 // const searchQuery = 'Google';
36
37 const {SearchServiceClient} = require('@google-cloud/discoveryengine').v1beta;
38
39 // For more information, refer to:
40 // https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
41 const apiEndpoint =
42 location === 'global'
43 ? 'discoveryengine.googleapis.com'
44 : `${location}-discoveryengine.googleapis.com`;
45
46 // Instantiates a client
47 const client = new SearchServiceClient({apiEndpoint: apiEndpoint});
48
49 async function search() {
50 // The full resource name of the search engine serving configuration.
51 // Example: projects/{projectId}/locations/{location}/collections/{collectionId}/dataStores/{dataStoreId}/servingConfigs/{servingConfigId}
52 // You must create a search engine in the Cloud Console first.
53 const name = client.projectLocationCollectionDataStoreServingConfigPath(
54 projectId,
55 location,
56 collectionId,
57 dataStoreId,
58 servingConfigId
59 );
60
61 const request = {
62 pageSize: 10,
63 query: searchQuery,
64 servingConfig: name,
65 };
66
67 const IResponseParams = {
68 ISearchResult: 0,
69 ISearchRequest: 1,
70 ISearchResponse: 2,
71 };
72
73 // Perform search request
74 const response = await client.search(request, {
75 // Warning: Should always disable autoPaginate to avoid iterate through all pages.

Callers 1

search.jsFile · 0.70

Calls 1

searchFunction · 0.85

Tested by

no test coverage detected