정형 데이터 또는 메타데이터가 포함된 비정형 데이터를 사용하는 검색 앱이 있는 경우 메타데이터를 사용하여 검색어를 필터링할 수 있습니다. 이 페이지에서는 메타데이터 필드를 사용하여 검색을 특정 문서 집합으로 제한하는 방법을 설명합니다.
시작하기 전에
앱을 만들고 정형 데이터 또는 메타데이터가 포함된 비정형 데이터를 수집했는지 확인합니다. 자세한 내용은 검색 앱 만들기를 참조하세요.
메타데이터 예시
PDF 파일 4개 (document_1.pdf, document_2.pdf, document_3.pdf, document_4.pdf)의 메타데이터 예를 검토하세요. 이 메타데이터는 PDF 파일과 함께 Cloud Storage 버킷의 JSON 파일에 있습니다. 이 페이지를 읽으면서 이 예시를 다시 참조할 수 있습니다.
{"id": "1", "structData": {"title": "Policy on accepting corrected claims", "category": ["persona_A"]}, "content": {"mimeType": "application/pdf", "uri": "gs://bucketname_87654321/data/document_1.pdf"}}
{"id": "2", "structData": {"title": "Claims documentation and reporting guidelines for commercial members", "category": ["persona_A", "persona_B"]}, "content": {"mimeType": "application/pdf", "uri": "gs://bucketname_87654321/data/document_2.pdf"}}
{"id": "3", "structData": {"title": "Claims guidelines for bundled services and supplies for commercial members", "category": ["persona_B", "persona_C"]}, "content": {"mimeType": "application/pdf", "uri": "gs://bucketname_87654321/data/document_3.pdf"}}
{"id": "4", "structData": {"title": "Advantage claims submission guidelines", "category": ["persona_A", "persona_C"]}, "content": {"mimeType": "application/pdf", "uri": "gs://bucketname_87654321/data/document_4.pdf"}}
필터 표현식 구문
검색 필터를 정의하는 데 사용할 필터 표현식의 구문을 이해해야 합니다. 필터 표현식 구문은 다음 Extended Backus–Naur Form으로 요약할 수 있습니다.
# A single expression or multiple expressions that are joined by "AND" or "OR". filter = expression, { " AND " | "OR", expression }; # Expressions can be prefixed with "-" or "NOT" to express a negation. expression = [ "-" | "NOT " ], # A parenthetical expression. | "(", expression, ")" # A simple expression applying to a text field. # Function "ANY" returns true if the field exactly matches any of the literals. ( text_field, ":", "ANY", "(", literal, { ",", literal }, ")" # A simple expression applying to a numerical field. Function "IN" returns true # if a field value is within the range. By default, lower_bound is inclusive and # upper_bound is exclusive. | numerical_field, ":", "IN", "(", lower_bound, ",", upper_bound, ")" # A simple expression that applies to a numerical field and compares with a double value. | numerical_field, comparison, double # An expression that applies to a geolocation field with text/street/postal address. | geolocation_field, ":", "GEO_DISTANCE(", literal, ",", distance_in_meters, ")" # An expression that applies to a geolocation field with latitude and longitude. | geolocation_field, ":", "GEO_DISTANCE(", latitude_double, ",", longitude_double, ",", distance_in_meters, ")" # Datetime field | datetime_field, comparison, literal_iso_8601_datetime_format); # A lower_bound is either a double or "*", which represents negative infinity. # Explicitly specify inclusive bound with the character 'i' or exclusive bound # with the character 'e'. lower_bound = ( double, [ "e" | "i" ] ) | "*"; # An upper_bound is either a double or "*", which represents infinity. # Explicitly specify inclusive bound with the character 'i' or exclusive bound # with the character 'e'. upper_bound = ( double, [ "e" | "i" ] ) | "*"; # Supported comparison operators. comparison = "<=" | "<" | ">=" | ">" | "="; # A literal is any double quoted string. You must escape backslash (\) and # quote (") characters. literal = double quoted string; text_field = text field - for example, category; numerical_field = numerical field - for example, score; geolocation_field = field of geolocation data type - for example home_address, location; datetime_field = field of datetime data type - for example creation_date, expires_on; literal_iso_8601_datetime_format = either a double quoted string representing ISO 8601 datetime or a numerical field representing microseconds from unix epoch.
메타데이터 필터를 사용하여 검색
메타데이터 필터를 사용하여 검색하려면 다음 단계를 따르세요.
검색어를 필터링하는 데 사용할 메타데이터 필드를 확인합니다.
예를 들어 시작하기 전에의 메타데이터에서는
category필드를 검색 필터로 사용할 수 있습니다. 메타데이터 예와 같이 구조화된 데이터를 필터링할 때는 필드의 전체 경로(structData.category)를 지정합니다. 그런 다음 사용자가persona_A,persona_B또는persona_C를 기준으로 필터링할 수 있으므로 관심 있는 페르소나와 관련된 문서로만 검색이 제한됩니다.메타데이터 필드의 색인 생성이 가능하도록 설정합니다.
앱 ID를 찾습니다. 앱 ID를 이미 알고 있는 경우 다음 단계로 건너뜁니다.
Google Cloud 콘솔에서 AI 애플리케이션 페이지로 이동합니다.
앱 페이지에서 앱 이름을 찾고 ID 열에서 앱 ID를 가져옵니다.
검색 결과를 가져옵니다.
curl -X POST -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/engines/APP_ID/servingConfigs/default_search:search" \ -d '{ "query": "QUERY", "filter": "FILTER" }'다음을 바꿉니다.
PROJECT_ID: 프로젝트의 ID입니다.APP_ID: 앱의 ID입니다.QUERY: 검색할 쿼리 텍스트입니다.FILTER: 선택사항입니다. 필터 표현식 구문을 사용하여 지정된 필드 집합을 기준으로 필터링할 수 있는 텍스트 필드입니다. 기본값은 빈 문자열로, 필터가 적용되지 않음을 의미합니다.
예를 들어 시작하기 전에에서 메타데이터가 포함된 PDF 파일 4개를 가져왔다고 가정해 보겠습니다. 'claims'라는 단어가 포함된 문서를 검색하고
category값이persona_A인 문서만 쿼리하려고 합니다. 호출에 다음 문을 포함하면 됩니다."query": "claims", "filter": "category: ANY(\"persona_A\")"자세한 내용은 정형 데이터 또는 비정형 데이터가 있는 앱의 검색 결과 가져오기의 REST 탭을 참고하세요.
클릭하여 응답 예시를 확인하세요.
위의 절차와 같이 검색을 수행하면 다음과 유사한 응답이 표시됩니다. 응답에는
category값이persona_A인 세 문서가 포함되어 있습니다.{ "results": [ { "id": "2", "document": { "name": "projects/abcdefg/locations/global/collections/default_collection/dataStores/search_store_id/branches/0/documents/2", "id": "2", "structData": { "title": "Claims documentation and reporting guidelines for commercial members", "category": [ "persona_A", "persona_B" ] }, "derivedStructData": { "link": "gs://bucketname_87654321/data/document_2.pdf", "extractive_answers": [ { "pageNumber": "1", "content": "lorem ipsum" } ] } } }, { "id": "1", "document": { "name": "projects/abcdefg/locations/global/collections/default_collection/dataStores/search_store_id/branches/0/documents/1", "id": "1", "structData": { "title": "Policy on accepting corrected claims", "category": [ "persona_A" ] }, "derivedStructData": { "extractive_answers": [ { "pageNumber": "2", "content": "lorem ipsum" } ], "link": "gs://bucketname_87654321/data/document_1.pdf" } } }, { "id": "4", "document": { "name": "projects/abcdefg/locations/global/collections/default_collection/dataStores/search_store_id/branches/0/documents/4", "id": "4", "structData": { "title": "Advantage claims submission guidelines", "category": [ "persona_A", "persona_C" ] }, "derivedStructData": { "extractive_answers": [ { "pageNumber": "47", "content": "lorem ipsum" } ], "link": "gs://bucketname_87654321/data/document_4.pdf" } } } ], "totalSize": 330, "attributionToken": "UvBRCgsI26PxpQYQs7vQZRIkNjRiYWY1MTItMDAwMC0yZWIwLTg3MTAtMTQyMjNiYzYzMWEyIgdHRU5FUklDKhSOvp0VpovvF8XL8xfC8J4V1LKdFQ", "guidedSearchResult": {}, "summary": {} }
필터 표현식의 예
다음 표에는 필터 표현식의 예가 나와 있습니다.
| 필터 | 다음과 같은 문서의 결과만 반환합니다. |
|---|---|
category: ANY("persona_A") |
텍스트 필드 category이(가) persona_A입니다. |
score: IN(*, 100.0e) |
숫자 필드 score가 음의 무한대보다 크고 100.0보다 작습니다. |
non-smoking = "true" |
불리언 non-smoking이 true입니다. |
pet-friendly = "false" |
불리언 pet-friendly이 false입니다. |
manufactured_date = "2023" |
manufactured date이 2023년 중 언제든지 |
manufactured_date >= "2024-04-16" |
manufactured_date는 2024년 4월 16일 이후입니다. |
manufactured_date < "2024-04-16T12:00:00-07:00" |
manufactured_date는 2024년 4월 16일 태평양 일광 절약 표준시를 기준으로 정오 이전입니다. |
office.location:GEO_DISTANCE("1600 Amphitheater Pkwy, Mountain View, CA, 94043", 500) |
위치정보 필드 office.location은 1600 Amphitheatre Pkwy에서 500m 거리 이내입니다. |
NOT office.location:GEO_DISTANCE("Palo Alto, CA", 1000) |
위치정보 필드 office.location은 캘리포니아주 팔로알토에서 1km 반경 이내입니다. |
office.location:GEO_DISTANCE(34.1829, -121.293, 500) |
위치정보 필드 office.location는 위도 34.1829, 경도 -121.293의 500m 반경 이내입니다. |
category: ANY("persona_A") AND score: IN(*, 100.0e) |
category가 persona_A이고 score가 100보다 작습니다. |
office.location:GEO_DISTANCE("Mountain View, CA", 500) OR office.location:GEO_DISTANCE("Palo Alto, CA", 500) |
office.location은 마운틴뷰 또는 팔로알토에서 500m 거래 이내입니다. |
(price<175 AND pet-friendly = "true") OR (price<125 AND pet-friendly = "false") |
price가 175보다 낮으면 반려동물을 동반할 수 있고, price가 125보다 낮으면 반려동물을 동반할 수 없습니다. |
다음 단계
- 필터가 검색 품질에 미치는 영향을 이해하려면 검색 품질을 평가하세요. 자세한 내용은 검색 품질 평가를 참조하세요.