Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An error raises when I call search request API of discovery engine with ContentSearchSpec #26036

Closed
tsugumi-sys opened this issue Jun 3, 2024 · 3 comments
Assignees

Comments

@tsugumi-sys
Copy link

tsugumi-sys commented Jun 3, 2024

Environment details

  • OS: Sonoma 14.4.1
  • Ruby version: 3.2.2
  • Gem name and version: google-cloud-discovery_engine-v1 (0.8.0)

Code example

# document: https://cloud.google.com/ruby/docs/reference/google-cloud-discovery_engine-v1/0.1.0
require 'google/cloud/discovery_engine/v1'

class VertexAIRepository
  class << self
    def search_event_ids(search_query:)
      client = initialize_search_client
      request = build_search_request(search_query:)
      fetch_event_ids_from_vertex_ai(client:, request:)
    end

    private

    def initialize_search_client
      service_account_creds = ENV.fetch('GOOGLE_CLOUD_CREDENTIALS')
      begin
        secret_data = JSON.parse(service_account_creds)
      rescue JSON::ParserError => e
        raise "Error parsing JSON secret string: #{e.message}"
      end

      Google::Cloud::DiscoveryEngine::V1::DocumentService::Client.configure do |config|
        config.credentials = Google::Auth::Credentials.new(secret_data)
      end
      Google::Cloud::DiscoveryEngine::V1::SearchService::Client.new
    end

    def build_search_request(search_query:)
      gcp_project_id = ENV.fetch('GOOGLE_CLOUD_PROJECT_ID')
      vertex_ai_engine_id = ENV.fetch('VERTEX_AI_ENGINE_ID')

      serving_config = "projects/#{gcp_project_id}/locations/global/collections/default_collection/engines/#{vertex_ai_engine_id}/servingConfigs/default_config"
      content_search_spec = Google::Cloud::DiscoveryEngine::V1::SearchRequest::ContentSearchSpec.new(
        snippet_spec: Google::Cloud::DiscoveryEngine::V1::SearchRequest::ContentSearchSpec::SnippetSpec.new
        # NOTE: summary spec is not currently supproted for Ruby sdk.
      )
      # Create a request. To set request fields, pass in keyword arguments.
      Google::Cloud::DiscoveryEngine::V1::SearchRequest.new(
        serving_config:, query: search_query, page_size: 10, content_search_spec: # error raises here.
      )
    end

    def fetch_event_ids_from_vertex_ai(client:, request:)
      event_ids = []
      begin
        result = client.search request
        result.each do |item|
          event_ids.push(item.to_h[:id])
        end
        event_ids
      rescue Google::Cloud::Error => e
        Rails.logger.error e.message
        Sentry.capture_message(e.message)
      end
      event_ids
    end
  end
end

Error message:

3:ContentSearchSpec can only be set in a SearchRequest searching against content search enabled DataStore.. debug_error_string:{UNKNOWN:Error received from peer ipv4:xxx.xxx.xxx.xxx {created_time:"2024-06-03T09:15:34.59707936+00:00", grpc_status:3, grpc_message:"ContentSearchSpec can only be set in a SearchRequest searching against content search enabled DataStore."}}

This error started occurring on 5/31. I assume that the release on 5/31 may be related to this error but I could not find out some changes around ContentSearchSpec module.

When I stopped using ContentSearchSpec, the error has gone.

Is this a bug or there were some breaking changes in sdk?

@jostjerome
Copy link

hello. I have same issue since 5/27. Did you found cause and solution please ?

@jostjerome
Copy link

Hello. I had answer from GCP support. In my case, it's due to I used ContentSearchSpec on structured data store. ContentSearchSpec is only ruanable on unstructured datastore. Hope it can help you !

@tsugumi-sys
Copy link
Author

tsugumi-sys commented Jun 19, 2024

@jostjerome
thanks :) I understand! It's not a bug, so I close my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants