|
32 | 32 | - [Function calling](#function-calling) |
33 | 33 | - [Code Execution](#code-execution) |
34 | 34 | - [Grounding with Google Search](#grounding-with-google-search) |
| 35 | + - [Grounding with Google Maps](#grounding-with-google-maps) |
| 36 | + - [Grounding with File Search](#grounding-with-file-search) |
35 | 37 | - [System Instructions](#system-instructions) |
36 | 38 | - [Speech generation](#speech-generation) |
37 | 39 | - [Thinking Mode](#thinking-mode) |
|
49 | 51 | - [Update Cached Content](#update-cached-content) |
50 | 52 | - [Delete Cached Content](#delete-cached-content) |
51 | 53 | - [Use Cached Content](#use-cached-content) |
| 54 | + - [File Search Stores](#file-search-stores) |
| 55 | + - [Create File Search Store](#create-file-search-store) |
| 56 | + - [Get File Search Store](#get-file-search-store) |
| 57 | + - [List File Search Stores](#list-file-search-stores) |
| 58 | + - [Delete File Search Store](#delete-file-search-store) |
| 59 | + - [Update File Search Store](#update-file-search-store) |
| 60 | + - [File Search Documents](#file-search-documents) |
| 61 | + - [Create File Search Document](#create-file-search-document) |
| 62 | + - [Get File Search Document](#get-file-search-document) |
| 63 | + - [List File Search Documents](#list-file-search-documents) |
| 64 | + - [Delete File Search Document](#delete-file-search-document) |
52 | 65 | - [Embedding Resource](#embedding-resource) |
53 | 66 | - [Models](#models) |
54 | 67 | - [List Models](#list-models) |
@@ -482,6 +495,59 @@ if ($groundingMetadata !== null) { |
482 | 495 | } |
483 | 496 | ``` |
484 | 497 |
|
| 498 | +#### Grounding with Google Maps |
| 499 | +Grounding with Google Maps allows the model to utilize real-world geographical data. This enables more precise location-based responses, such as finding nearby points of interest. |
| 500 | + |
| 501 | +```php |
| 502 | +use Gemini\Data\GoogleMaps; |
| 503 | +use Gemini\Data\RetrievalConfig; |
| 504 | +use Gemini\Data\Tool; |
| 505 | +use Gemini\Data\ToolConfig; |
| 506 | + |
| 507 | +$tool = new Tool( |
| 508 | + googleMaps: new GoogleMaps(enableWidget: true) |
| 509 | +); |
| 510 | + |
| 511 | +$toolConfig = new ToolConfig( |
| 512 | + retrievalConfig: new RetrievalConfig( |
| 513 | + latitude: 40.758896, |
| 514 | + longitude: -73.985130 |
| 515 | + ) |
| 516 | +); |
| 517 | + |
| 518 | +$response = $client |
| 519 | + ->generativeModel(model: 'gemini-2.0-flash') |
| 520 | + ->withTool($tool) |
| 521 | + ->withToolConfig($toolConfig) |
| 522 | + ->generateContent('Find coffee shops near me'); |
| 523 | + |
| 524 | +echo $response->text(); |
| 525 | +// (Model output referencing coffee shops) |
| 526 | +``` |
| 527 | + |
| 528 | +#### Grounding with File Search |
| 529 | +Grounding with File Search enables the model to retrieve and utilize information from your indexed files. This is useful for answering questions based on private or extensive document collections. |
| 530 | + |
| 531 | +```php |
| 532 | +use Gemini\Data\FileSearch; |
| 533 | +use Gemini\Data\Tool; |
| 534 | + |
| 535 | +$tool = new Tool( |
| 536 | + fileSearch: new FileSearch( |
| 537 | + fileSearchStoreNames: ['files/my-document-store'], |
| 538 | + metadataFilter: 'author = "Robert Graves"' |
| 539 | + ) |
| 540 | +); |
| 541 | + |
| 542 | +$response = $client |
| 543 | + ->generativeModel(model: 'gemini-2.0-flash') |
| 544 | + ->withTool($tool) |
| 545 | + ->generateContent('Summarize the document about Greek myths by Robert Graves'); |
| 546 | + |
| 547 | +echo $response->text(); |
| 548 | +// (Model output summarizing the document) |
| 549 | +``` |
| 550 | + |
485 | 551 | #### System Instructions |
486 | 552 | System instructions let you steer the behavior of the model based on your specific needs and use cases. You can set the role and personality of the model, define the format of responses, and provide goals and guardrails for model behavior. |
487 | 553 |
|
@@ -631,6 +697,7 @@ Every prompt you send to the model includes parameter values that control how th |
631 | 697 |
|
632 | 698 | Also, you can use safety settings to adjust the likelihood of getting responses that may be considered harmful. By default, safety settings block content with medium and/or high probability of being unsafe content across all dimensions. Learn more about [safety settings](https://ai.google.dev/docs/concepts#safety_setting). |
633 | 699 |
|
| 700 | +When using tools like `GoogleMaps`, you may also provide additional configuration via `ToolConfig`, such as `RetrievalConfig` for geographical context. |
634 | 701 |
|
635 | 702 | ```php |
636 | 703 | use Gemini\Data\GenerationConfig; |
@@ -834,6 +901,125 @@ echo "Cached tokens used: {$response->usageMetadata->cachedContentTokenCount}\n" |
834 | 901 | echo "New tokens used: {$response->usageMetadata->promptTokenCount}\n"; |
835 | 902 | ``` |
836 | 903 |
|
| 904 | +### File Search Stores |
| 905 | + |
| 906 | +File search allows you to search files that were uploaded through the File API. |
| 907 | + |
| 908 | +#### Create File Search Store |
| 909 | +Create a file search store. |
| 910 | + |
| 911 | +```php |
| 912 | +use Gemini\Enums\FileState; |
| 913 | +use Gemini\Enums\MimeType; |
| 914 | +use Gemini\Enums\Schema; |
| 915 | +use Gemini\Enums\DataType; |
| 916 | + |
| 917 | +$files = $client->files(); |
| 918 | +echo "Uploading\n"; |
| 919 | +$meta = $files->upload( |
| 920 | + filename: 'document.pdf', |
| 921 | + mimeType: MimeType::APPLICATION_PDF, |
| 922 | + displayName: 'Document for search' |
| 923 | +); |
| 924 | +echo "Processing"; |
| 925 | +do { |
| 926 | + echo "."; |
| 927 | + sleep(2); |
| 928 | + $meta = $files->metadataGet($meta->uri); |
| 929 | +} while (! $meta->state->complete()); |
| 930 | +echo "\n"; |
| 931 | + |
| 932 | +if ($meta->state == FileState::Failed) { |
| 933 | + die("Upload failed:\n".json_encode($meta->toArray(), JSON_PRETTY_PRINT)); |
| 934 | +} |
| 935 | + |
| 936 | +$fileSearchStore = $client->fileSearchStores()->create( |
| 937 | + displayName: 'My Search Store', |
| 938 | +); |
| 939 | + |
| 940 | +echo "File search store created: {$fileSearchStore->name}\n"; |
| 941 | +``` |
| 942 | + |
| 943 | +#### Get File Search Store |
| 944 | +Get a specific file search store by name. |
| 945 | + |
| 946 | +```php |
| 947 | +$fileSearchStore = $client->fileSearchStores()->get('fileSearchStores/my-search-store'); |
| 948 | + |
| 949 | +echo "Name: {$fileSearchStore->name}\n"; |
| 950 | +echo "Display Name: {$fileSearchStore->displayName}\n"; |
| 951 | +``` |
| 952 | + |
| 953 | +#### List File Search Stores |
| 954 | +List all file search stores. |
| 955 | + |
| 956 | +```php |
| 957 | +$response = $client->fileSearchStores()->list(pageSize: 10); |
| 958 | + |
| 959 | +foreach ($response->fileSearchStores as $fileSearchStore) { |
| 960 | + echo "Name: {$fileSearchStore->name}\n"; |
| 961 | + echo "Display Name: {$fileSearchStore->displayName}\n"; |
| 962 | + echo "--- \n"; |
| 963 | +} |
| 964 | +``` |
| 965 | + |
| 966 | +#### Delete File Search Store |
| 967 | +Delete a file search store by name. |
| 968 | + |
| 969 | +```php |
| 970 | +$client->fileSearchStores()->delete('fileSearchStores/my-search-store'); |
| 971 | +``` |
| 972 | + |
| 973 | +### File Search Documents |
| 974 | + |
| 975 | +#### Upload File Search Document |
| 976 | +Upload a local file directly to a file search store. |
| 977 | + |
| 978 | +```php |
| 979 | +use Gemini\Enums\MimeType; |
| 980 | + |
| 981 | +$response = $client->fileSearchStores()->upload( |
| 982 | + storeName: 'fileSearchStores/my-search-store', |
| 983 | + filename: 'document2.pdf', |
| 984 | + mimeType: MimeType::APPLICATION_PDF, |
| 985 | + displayName: 'Another Search Document' |
| 986 | +); |
| 987 | + |
| 988 | +echo "File search document upload operation: {$response->name}\n"; |
| 989 | +``` |
| 990 | + |
| 991 | +#### Get File Search Document |
| 992 | +Get a specific file search document by name. |
| 993 | + |
| 994 | +```php |
| 995 | +$fileSearchDocument = $client->fileSearchStores()->getDocument('fileSearchStores/my-search-store/fileSearchDocuments/my-document'); |
| 996 | + |
| 997 | +echo "Name: {$fileSearchDocument->name}\n"; |
| 998 | +echo "Display Name: {$fileSearchDocument->displayName}\n"; |
| 999 | +``` |
| 1000 | + |
| 1001 | +#### List File Search Documents |
| 1002 | +List all file search documents within a store. |
| 1003 | + |
| 1004 | +```php |
| 1005 | +$response = $client->fileSearchStores()->listDocuments(storeName: 'fileSearchStores/my-search-store', pageSize: 10); |
| 1006 | + |
| 1007 | +foreach ($response->documents as $fileSearchDocument) { |
| 1008 | + echo "Name: {$fileSearchDocument->name}\n"; |
| 1009 | + echo "Display Name: {$fileSearchDocument->displayName}\n"; |
| 1010 | + echo "Create Time: {$fileSearchDocument->createTime}\n"; |
| 1011 | + echo "Update Time: {$fileSearchDocument->updateTime}\n"; |
| 1012 | + echo "--- \n"; |
| 1013 | +} |
| 1014 | +``` |
| 1015 | + |
| 1016 | +#### Delete File Search Document |
| 1017 | +Delete a file search document by name. |
| 1018 | + |
| 1019 | +```php |
| 1020 | +$client->fileSearchStores()->deleteDocument('fileSearchStores/my-search-store/fileSearchDocuments/my-document'); |
| 1021 | +``` |
| 1022 | + |
837 | 1023 | ### Embedding Resource |
838 | 1024 | Embedding is a technique used to represent information as a list of floating point numbers in an array. With Gemini, you can represent text (words, sentences, and blocks of text) in a vectorized form, making it easier to compare and contrast embeddings. For example, two texts that share a similar subject matter or sentiment should have similar embeddings, which can be identified through mathematical comparison techniques such as cosine similarity. |
839 | 1025 |
|
|
0 commit comments