फ़ाइल खोजने की सुविधा

Gemini API, फ़ाइल खोजने वाले टूल की मदद से, रीट्रिवल ऑगमेंटेड जनरेशन ("आरएजी") की सुविधा देता है. File Search, आपके डेटा को इंपोर्ट करता है, उसे छोटे-छोटे हिस्सों में बांटता है, और इंडेक्स करता है. इससे, उपयोगकर्ता के प्रॉम्प्ट के आधार पर काम की जानकारी को तेज़ी से वापस पाने में मदद मिलती है. इसके बाद, इस जानकारी को मॉडल को कॉन्टेक्स्ट के तौर पर दिया जाता है. इससे मॉडल को ज़्यादा सटीक और काम के जवाब देने में मदद मिलती है.

uploadToFileSearchStore एपीआई का इस्तेमाल करके, किसी मौजूदा फ़ाइल को सीधे तौर पर File Search स्टोर में अपलोड किया जा सकता है. इसके अलावा, फ़ाइल को अलग से अपलोड करने के बाद, उसे importFile किया जा सकता है. ऐसा तब करें, जब आपको फ़ाइल को एक साथ बनाना हो.

फ़ाइल खोज स्टोर में सीधे अपलोड करें

इस उदाहरण में, फ़ाइल स्टोर में फ़ाइल को सीधे तौर पर अपलोड करने का तरीका बताया गया है:

Python

from google import genai
from google.genai import types
import time

client = genai.Client()

# Create the File Search store with an optional display name
file_search_store = client.file_search_stores.create(config={'display_name': 'your-fileSearchStore-name'})

# Upload and import a file into the File Search store, supply a file name which will be visible in citations
operation = client.file_search_stores.upload_to_file_search_store(
  file='sample.txt',
  file_search_store_name=file_search_store.name,
  config={
      'display_name' : 'display-file-name',
  }
)

# Wait until import is complete
while not operation.done:
    time.sleep(5)
    operation = client.operations.get(operation)

# Ask a question about the file
response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents="""Can you tell me about Robert Graves""",
    config=types.GenerateContentConfig(
        tools=[
            file_search=(
                  file_search_store_names=[file_search_store.name]
            )
        ]
    )
)

print(response.text)

JavaScript

const { GoogleGenAI } = require('@google/genai');

const ai = new GoogleGenAI({});

async function run() {
  // Create the File Search store with an optional display name
  const fileSearchStore = await ai.fileSearchStores.create({
    config: { displayName: 'your-fileSearchStore-name' }
  });

  // Upload and import a file into the File Search store, supply a file name which will be visible in citations
  let operation = await ai.fileSearchStores.uploadToFileSearchStore({
    file: 'file.txt',
    fileSearchStoreName: fileSearchStore.name,
    config: {
      displayName: 'file-name',
    }
  });

  // Wait until import is complete
  while (!operation.done) {
    await new Promise(resolve => setTimeout(resolve, 5000));
    operation = await ai.operations.get({ operation });
  }

  // Ask a question about the file
  const response = await ai.models.generateContent({
    model: "gemini-2.5-flash",
    contents: "Can you tell me about Robert Graves",
    config: {
      tools: [
        {
          fileSearch: {
            fileSearchStoreNames: [fileSearchStore.name]
          }
        }
      ]
    }
  });

  console.log(response.text);
}

run();

REST

FILE_PATH="path/to/sample.pdf"
MIME_TYPE=$(file -b --mime-type "${FILE_PATH}")
NUM_BYTES=$(wc -c < "${FILE_PATH}")

# Create a FileSearchStore
STORE_RESPONSE=$(curl -s -X POST "https://generativelanguage.googleapis.com/v1beta/fileSearchStores?key=${GEMINI_API_KEY}" \
    -H "Content-Type: application/json" \
    -d '{ "displayName": "My Store" }')

# Extract the store name (format: fileSearchStores/xxxxxxx)
STORE_NAME=$(echo $STORE_RESPONSE | jq -r '.name')

# Initiate Resumable Upload to the Store
TMP_HEADER="upload-header.tmp"

curl -s -D "${TMP_HEADER}" \ "https://generativelanguage.googleapis.com/upload/v1beta/${STORE_NAME}:uploadToFileSearchStore?key=${GEMINI_API_KEY}" \
  -H "X-Goog-Upload-Protocol: resumable" \
  -H "X-Goog-Upload-Command: start" \
  -H "X-Goog-Upload-Header-Content-Length: ${NUM_BYTES}" \
  -H "X-Goog-Upload-Header-Content-Type: ${MIME_TYPE}" \
  -H "Content-Type: application/json" > /dev/null

# Extract upload_url from headers
UPLOAD_URL=$(grep -i "x-goog-upload-url: " "${TMP_HEADER}" | cut -d" " -f2 | tr -d "\r")
rm "${TMP_HEADER}"

# --- Upload the actual bytes ---
curl "${UPLOAD_URL}" \
  -H "Content-Length: ${NUM_BYTES}" \
  -H "X-Goog-Upload-Offset: 0" \
  -H "X-Goog-Upload-Command: upload, finalize" \
  --data-binary "@${FILE_PATH}" 2> /dev/null

# Generate content using the FileSearchStore
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent" \
    -H "x-goog-api-key: $GEMINI_API_KEY" \
    -H 'Content-Type: application/json' \
    -X POST \
    -d '{
            "contents": [{
                "parts":[{"text": "What does the research say about ..."}]          
            }],
            "tools": [{
                "file_search": { "file_search_store_names":["'$STORE_NAME'"] }
            }]
        }' 2> /dev/null > response.json

cat response.json

ज़्यादा जानकारी के लिए, uploadToFileSearchStore का एपीआई रेफ़रंस देखें.

फ़ाइलें इंपोर्ट करना

इसके अलावा, किसी मौजूदा फ़ाइल को अपलोड करके, उसे अपने फ़ाइल स्टोर में इंपोर्ट किया जा सकता है:

Python

from google import genai
from google.genai import types
import time

client = genai.Client()

# Upload the file using the Files API, supply a file name which will be visible in citations
sample_file = client.files.upload(file='sample.txt', config={'name': 'display_file_name'})

# Create the File Search store with an optional display name
file_search_store = client.file_search_stores.create(config={'display_name': 'your-fileSearchStore-name'})

# Import the file into the File Search store
operation = client.file_search_stores.import_file(
    file_search_store_name=file_search_store.name,
    file_name=sample_file.name
)

# Wait until import is complete
while not operation.done:
    time.sleep(5)
    operation = client.operations.get(operation)

# Ask a question about the file
response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents="""Can you tell me about Robert Graves""",
    config=types.GenerateContentConfig(
        tools=[
            file_search=(
                  file_search_store_names=[file_search_store.name]
            )
        ]
    )
)

print(response.text)

JavaScript

const { GoogleGenAI } = require('@google/genai');

const ai = new GoogleGenAI({});

async function run() {
  // Upload the file using the Files API, supply a file name which will be visible in citations
  const sampleFile = await ai.files.upload({
    file: 'sample.txt',
    config: { name: 'file-name' }
  });

  // Create the File Search store with an optional display name
  const fileSearchStore = await ai.fileSearchStores.create({
    config: { displayName: 'your-fileSearchStore-name' }
  });

  // Import the file into the File Search store
  let operation = await ai.fileSearchStores.importFile({
    fileSearchStoreName: fileSearchStore.name,
    fileName: sampleFile.name
  });

  // Wait until import is complete
  while (!operation.done) {
    await new Promise(resolve => setTimeout(resolve, 5000));
    operation = await ai.operations.get({ operation: operation });
  }

  // Ask a question about the file
  const response = await ai.models.generateContent({
    model: "gemini-2.5-flash",
    contents: "Can you tell me about Robert Graves",
    config: {
      tools: [
        {
          fileSearch: {
            fileSearchStoreNames: [fileSearchStore.name]
          }
        }
      ]
    }
  });

  console.log(response.text);
}

run();

REST

FILE_PATH="path/to/sample.pdf"
MIME_TYPE=$(file -b --mime-type "${FILE_PATH}")
NUM_BYTES=$(wc -c < "${FILE_PATH}")

# Create a FileSearchStore
STORE_RESPONSE=$(curl -s -X POST "https://generativelanguage.googleapis.com/v1beta/fileSearchStores?key=${GEMINI_API_KEY}" \
    -H "Content-Type: application/json" \
    -d '{ "displayName": "My Store" }')

STORE_NAME=$(echo $STORE_RESPONSE | jq -r '.name')

# Initiate Resumable Upload to the Store
TMP_HEADER="upload-header.tmp"

curl -s -X POST "https://generativelanguage.googleapis.com/upload/v1beta/files?key=${GEMINI_API_KEY}" \
  -D "${TMP_HEADER}" \
  -H "X-Goog-Upload-Protocol: resumable" \
  -H "X-Goog-Upload-Command: start" \
  -H "X-Goog-Upload-Header-Content-Length: ${NUM_BYTES}" \
  -H "X-Goog-Upload-Header-Content-Type: ${MIME_TYPE}" \
  -H "Content-Type: application/json" 2> /dev/null

UPLOAD_URL=$(grep -i "x-goog-upload-url: " "${TMP_HEADER}" | cut -d" " -f2 | tr -d "\r")
rm "${TMP_HEADER}"

# Upload the actual bytes.
curl -s -X POST "${UPLOAD_URL}" \
  -H "Content-Length: ${NUM_BYTES}" \
  -H "X-Goog-Upload-Offset: 0" \
  -H "X-Goog-Upload-Command: upload, finalize" \
  --data-binary "@${FILE_PATH}" 2> /dev/null > file_info.json

file_uri=$(jq ".file.name" file_info.json)

# Import files into the file search store
operation_name=$(curl "https://generativelanguage.googleapis.com/v1beta/${STORE_NAME}:importFile?key=${GEMINI_API_KEY}" \
  -H "Content-Type: application/json" \
  -X POST \
  -d '{
        "file_name":'$file_uri'
    }' | jq -r .name)

# Wait for long running operation to complete
while true; do
  # Get the full JSON status and store it in a variable.
  status_response=$(curl -s -H "x-goog-api-key: $GEMINI_API_KEY" "https://generativelanguage.googleapis.com/v1beta/${operation_name}")

  # Check the "done" field from the JSON stored in the variable.
  is_done=$(echo "${status_response}" | jq .done)

  if [ "${is_done}" = "true" ]; then
    break
  fi
  # Wait for 10 seconds before checking again.
  sleep 10
done

# Generate content using the FileSearchStore
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${GEMINI_API_KEY}" \
    -H 'Content-Type: application/json' \
    -X POST \
    -d '{
            "contents": [{
                "parts":[{"text": "What does the research say about ..."}]          
            }],
            "tools": [{
                "file_search": { "file_search_store_names":["'$STORE_NAME'"] }
            }]
        }' 2> /dev/null > response.json

cat response.json

ज़्यादा जानकारी के लिए, importFile का एपीआई रेफ़रंस देखें.

कॉन्फ़िगरेशन को हिस्सों में बांटना

किसी फ़ाइल को File Search स्टोर में इंपोर्ट करने पर, वह अपने-आप छोटे-छोटे हिस्सों में बंट जाती है. साथ ही, उसे एंबेड, इंडेक्स, और File Search स्टोर में अपलोड कर दिया जाता है. अगर आपको चंकिंग की रणनीति पर ज़्यादा कंट्रोल चाहिए, तो chunking_config सेटिंग का इस्तेमाल करें. इससे, हर चंक के लिए ज़्यादा से ज़्यादा टोकन और ओवरलैप होने वाले टोकन की ज़्यादा से ज़्यादा संख्या सेट की जा सकती है.

Python

# Upload and import and upload the file into the File Search store with a custom chunking configuration
operation = client.file_search_stores.upload_to_file_search_store(
    file_search_store_name=file_search_store.name,
    file_name=sample_file.name,
    config={
        'chunking_config': {
          'white_space_config': {
            'max_tokens_per_chunk': 200,
            'max_overlap_tokens': 20
          }
        }
    }
)

JavaScript

// Upload and import and upload the file into the File Search store with a custom chunking configuration
let operation = await ai.fileSearchStores.uploadToFileSearchStore({
  file: 'file.txt',
  fileSearchStoreName: fileSearchStore.name,
  config: {
    displayName: 'file-name',
    chunkingConfig: {
      whiteSpaceConfig: {
        maxTokensPerChunk: 200,
        maxOverlapTokens: 20
      }
    }
  }
});

REST

FILE_PATH="path/to/sample.pdf"
MIME_TYPE=$(file -b --mime-type "${FILE_PATH}")
NUM_BYTES=$(wc -c < "${FILE_PATH}")

# Create a FileSearchStore
STORE_RESPONSE=$(curl -s -X POST "https://generativelanguage.googleapis.com/v1beta/fileSearchStores?key=${GEMINI_API_KEY}" \
    -H "Content-Type: application/json" \
    -d '{ "displayName": "My Store" }')

# Extract the store name (format: fileSearchStores/xxxxxxx)
STORE_NAME=$(echo $STORE_RESPONSE | jq -r '.name')

# Initiate Resumable Upload to the Store
TMP_HEADER="upload-header.tmp"

curl -s -D "${TMP_HEADER}" \ "https://generativelanguage.googleapis.com/upload/v1beta/${STORE_NAME}:uploadToFileSearchStore?key=${GEMINI_API_KEY}" \
  -H "X-Goog-Upload-Protocol: resumable" \
  -H "X-Goog-Upload-Command: start" \
  -H "X-Goog-Upload-Header-Content-Length: ${NUM_BYTES}" \
  -H "X-Goog-Upload-Header-Content-Type: ${MIME_TYPE}" \
  -H "Content-Type: application/json" > /dev/null
  -d '{
        "chunking_config": {
          "white_space_config": {
            "max_tokens_per_chunk": 200,
            "max_overlap_tokens": 20
          }
        }
    }'

# Extract upload_url from headers
UPLOAD_URL=$(grep -i "x-goog-upload-url: " "${TMP_HEADER}" | cut -d" " -f2 | tr -d "\r")
rm "${TMP_HEADER}"

# --- Upload the actual bytes ---
curl "${UPLOAD_URL}" \
  -H "Content-Length: ${NUM_BYTES}" \
  -H "X-Goog-Upload-Offset: 0" \
  -H "X-Goog-Upload-Command: upload, finalize" \
  --data-binary "@${FILE_PATH}" 2> /dev/null

फ़ाइल खोजने की सुविधा वाले स्टोर का इस्तेमाल करने के लिए, इसे generateContent मेथड में टूल के तौर पर पास करें. इसके लिए, अपलोड करें और इंपोर्ट करें के उदाहरण देखें.

यह कैसे काम करता है

फ़ाइल खोज की सुविधा, सिमैंटिक सर्च नाम की तकनीक का इस्तेमाल करती है. इससे, उपयोगकर्ता के प्रॉम्प्ट से जुड़ी जानकारी ढूंढने में मदद मिलती है. कीवर्ड पर आधारित पारंपरिक खोज के उलट, सिमैंटिक सर्च आपकी क्वेरी के मतलब और कॉन्टेक्स्ट को समझती है.

किसी फ़ाइल को इंपोर्ट करने पर, उसे संख्या के तौर पर दिखाया जाता है. इसे एम्बेडिंग कहा जाता है. इससे टेक्स्ट के सिमैंटिक मतलब का पता चलता है. इन एम्बेडिंग को, फ़ाइल खोज के खास डेटाबेस में सेव किया जाता है. क्वेरी करने पर, उसे भी एम्बेडिंग में बदल दिया जाता है. इसके बाद, सिस्टम फ़ाइल खोज की सुविधा का इस्तेमाल करके, फ़ाइल खोज के स्टोर से मिलते-जुलते और काम के दस्तावेज़ के हिस्सों को ढूंढता है.

फ़ाइल खोजने की सुविधा वाले uploadToFileSearchStore एपीआई का इस्तेमाल करने की प्रोसेस के बारे में यहां बताया गया है:

  1. फ़ाइल खोज स्टोर बनाएं: फ़ाइल खोज स्टोर में, आपकी फ़ाइलों से प्रोसेस किया गया डेटा होता है. यह एम्बेडिंग के लिए परसिस्टेंट कंटेनर है. इस पर सिमैंटिक सर्च काम करेगी.

  2. कोई फ़ाइल अपलोड करना और उसे फ़ाइल खोजने वाले स्टोर में इंपोर्ट करना: एक साथ कोई फ़ाइल अपलोड करें और नतीजों को फ़ाइल खोजने वाले स्टोर में इंपोर्ट करें. इससे एक अस्थायी File ऑब्जेक्ट बनता है, जो आपके ओरिजनल दस्तावेज़ का रेफ़रंस होता है. इसके बाद, उस डेटा को छोटे-छोटे हिस्सों में बांटा जाता है. साथ ही, उसे फ़ाइल खोजने की सुविधा के लिए एम्बेड किए गए डेटा में बदलकर इंडेक्स किया जाता है. File ऑब्जेक्ट 48 घंटे बाद मिट जाता है. वहीं, फ़ाइल खोज में इंपोर्ट किया गया डेटा तब तक सेव रहेगा, जब तक आप उसे मिटाने का विकल्प नहीं चुनते.

  3. फ़ाइल खोजने की सुविधा के साथ क्वेरी: आखिर में, generateContent कॉल में FileSearch टूल का इस्तेमाल किया जाता है. टूल कॉन्फ़िगरेशन में, आपको एक FileSearchRetrievalResource तय करना होता है. यह FileSearchStore की ओर इशारा करता है, जिसे आपको खोजना है. इससे मॉडल को उस फ़ाइल सर्च स्टोर पर सिमैंटिक सर्च करने का निर्देश मिलता है, ताकि वह अपने जवाब के लिए काम की जानकारी ढूंढ सके.

फ़ाइल खोजने की सुविधा के लिए, इंडेक्स करने और क्वेरी करने की प्रोसेस
फ़ाइल खोजने की सुविधा के लिए, इंडेक्स करने और क्वेरी करने की प्रोसेस

इस डायग्राम में, दस्तावेज़ से एम्बेडिंग मॉडल तक की डॉटेड लाइन (gemini-embedding-001 का इस्तेमाल करके) uploadToFileSearchStore एपीआई को दिखाती है. इसमें फ़ाइल स्टोरेज को बायपास किया जाता है. इसके अलावा, Files API का इस्तेमाल करके, फ़ाइलों को अलग से बनाने और फिर इंपोर्ट करने से, इंडेक्सिंग की प्रोसेस दस्तावेज़ से फ़ाइल स्टोरेज और फिर एम्बेडिंग मॉडल पर चली जाती है.

फ़ाइल खोजें

फ़ाइल खोज की सुविधा वाला स्टोर, आपके दस्तावेज़ों के एम्बेड किए गए वर्शन के लिए कंटेनर होता है. File API के ज़रिए अपलोड की गई रॉ फ़ाइलें, 48 घंटे बाद मिट जाती हैं. हालांकि, फ़ाइल सर्च स्टोर में इंपोर्ट किया गया डेटा तब तक सेव रहता है, जब तक उसे मैन्युअल तरीके से नहीं मिटाया जाता. अपने दस्तावेज़ों को व्यवस्थित करने के लिए, एक से ज़्यादा फ़ाइल खोज स्टोर बनाए जा सकते हैं. FileSearchStore API की मदद से, फ़ाइल खोज स्टोर को मैनेज करने के लिए, फ़ाइल खोज स्टोर बनाए जा सकते हैं, उनकी सूची बनाई जा सकती है, उन्हें पाया जा सकता है, और उन्हें मिटाया जा सकता है. फ़ाइल खोज में स्टोर के नाम, दुनिया भर के लिए स्कोप किए जाते हैं.

यहां कुछ उदाहरण दिए गए हैं, जिनसे आपको File Search के स्टोर मैनेज करने के तरीके के बारे में जानकारी मिलेगी:

Python

# Create a File Search store (including optional display_name for easier reference)
file_search_store = client.file_search_stores.create(config={'display_name': 'my-file_search-store-123'})

# List all your File Search stores
for file_search_store in client.file_search_stores.list():
    print(file_search_store)

# Get a specific File Search store by name
my_file_search_store = client.file_search_stores.get(name='fileSearchStores/my-file_search-store-123')

# Delete a File Search store
client.file_search_stores.delete(name='fileSearchStores/my-file_search-store-123', config={'force': True})

JavaScript

// Create a File Search store (including optional display_name for easier reference)
const fileSearchStore = await ai.fileSearchStores.create({
  config: { displayName: 'my-file_search-store-123' }
});

// List all your File Search stores
const fileSearchStores = await ai.fileSearchStores.list();
for await (const store of fileSearchStores) {
  console.log(store);
}

// Get a specific File Search store by name
const myFileSearchStore = await ai.fileSearchStores.get({
  name: 'fileSearchStores/my-file_search-store-123'
});

// Delete a File Search store
await ai.fileSearchStores.delete({
  name: 'fileSearchStores/my-file_search-store-123',
  config: { force: true }
});

REST

# Create a File Search store (including optional display_name for easier reference)
curl -X POST "https://generativelanguage.googleapis.com/v1beta/fileSearchStores?key=${GEMINI_API_KEY}" \
    -H "Content-Type: application/json" 
    -d '{ "displayName": "My Store" }'

# List all your File Search stores
curl "https://generativelanguage.googleapis.com/v1beta/fileSearchStores?key=${GEMINI_API_KEY}" \

# Get a specific File Search store by name
curl "https://generativelanguage.googleapis.com/v1beta/fileSearchStores/my-file_search-store-123?key=${GEMINI_API_KEY}"

# Delete a File Search store
curl -X DELETE "https://generativelanguage.googleapis.com/v1beta/fileSearchStores/my-file_search-store-123?key=${GEMINI_API_KEY}"

File Search Documents API का रेफ़रंस. इसमें फ़ाइल स्टोर में दस्तावेज़ों को मैनेज करने से जुड़े तरीकों और फ़ील्ड के बारे में जानकारी दी गई है.

फ़ाइल का मेटाडेटा

फ़ाइलों को फ़िल्टर करने या उनके बारे में ज़्यादा जानकारी देने के लिए, उनमें कस्टम मेटाडेटा जोड़ा जा सकता है. मेटाडेटा, की-वैल्यू पेयर का एक सेट होता है.

Python

# Import the file into the File Search store with custom metadata
op = client.file_search_stores.import_file(
    file_search_store_name=file_search_store.name,
    file_name=sample_file.name,
    custom_metadata=[
        {"key": "author", "string_value": "Robert Graves"},
        {"key": "year", "numeric_value": 1934}
    ]
)

JavaScript

// Import the file into the File Search store with custom metadata
let operation = await ai.fileSearchStores.importFile({
  fileSearchStoreName: fileSearchStore.name,
  fileName: sampleFile.name,
  config: {
    customMetadata: [
      { key: "author", stringValue: "Robert Graves" },
      { key: "year", numericValue: 1934 }
    ]
  }
});

REST

FILE_PATH="path/to/sample.pdf"
MIME_TYPE=$(file -b --mime-type "${FILE_PATH}")
NUM_BYTES=$(wc -c < "${FILE_PATH}")

# Create a FileSearchStore
STORE_RESPONSE=$(curl -s -X POST "https://generativelanguage.googleapis.com/v1beta/fileSearchStores?key=${GEMINI_API_KEY}" \
    -H "Content-Type: application/json" \
    -d '{ "displayName": "My Store" }')

# Extract the store name (format: fileSearchStores/xxxxxxx)
STORE_NAME=$(echo $STORE_RESPONSE | jq -r '.name')

# Initiate Resumable Upload to the Store
TMP_HEADER="upload-header.tmp"

curl -s -D "${TMP_HEADER}" \
  "https://generativelanguage.googleapis.com/upload/v1beta/${STORE_NAME}:uploadToFileSearchStore?key=${GEMINI_API_KEY}" \
  -H "X-Goog-Upload-Protocol: resumable" \
  -H "X-Goog-Upload-Command: start" \
  -H "X-Goog-Upload-Header-Content-Length: ${NUM_BYTES}" \
  -H "X-Goog-Upload-Header-Content-Type: ${MIME_TYPE}" \
  -H "Content-Type: application/json" \
  -d '{
        "custom_metadata": [
          {"key": "author", "string_value": "Robert Graves"},
          {"key": "year", "numeric_value": 1934}
        ]
    }' > /dev/null

# Extract upload_url from headers
UPLOAD_URL=$(grep -i "x-goog-upload-url: " "${TMP_HEADER}" | cut -d" " -f2 | tr -d "\r")
rm "${TMP_HEADER}"

# --- Upload the actual bytes ---
curl "${UPLOAD_URL}" \
  -H "Content-Length: ${NUM_BYTES}" \
  -H "X-Goog-Upload-Offset: 0" \
  -H "X-Goog-Upload-Command: upload, finalize" \
  --data-binary "@${FILE_PATH}" 2> /dev/null

यह तब काम आता है, जब आपके पास फ़ाइल खोजने की सुविधा वाले स्टोर में कई दस्तावेज़ हों और आपको सिर्फ़ उनमें से कुछ दस्तावेज़ों को खोजना हो.

Python

# Use the metadata filter to search within a subset of documents
response = client.models.generate_content(
    model="gemini-2.5-flash",
    contents="Tell me about the book 'I, Claudius'",
    config=types.GenerateContentConfig(
        tools=[
            types.Tool(
                file_search=types.FileSearch(
                    file_search_store_names=[file_search_store.name],
                    metadata_filter="author=Robert Graves",
                )
            )
        ]
    )
)

print(response.text)

JavaScript

// Use the metadata filter to search within a subset of documents
const response = await ai.models.generateContent({
  model: "gemini-2.5-flash",
  contents: "Tell me about the book 'I, Claudius'",
  config: {
    tools: [
      {
        fileSearch: {
          fileSearchStoreNames: [fileSearchStore.name],
          metadataFilter: 'author="Robert Graves"',
        }
      }
    ]
  }
});

console.log(response.text);

REST

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${GEMINI_API_KEY}" \
    -H 'Content-Type: application/json' \
    -X POST \
    -d '{
            "contents": [{
                "parts":[{"text": "Tell me about the book I, Claudius"}]          
            }],
            "tools": [{
                "file_search": { 
                    "file_search_store_names":["'$STORE_NAME'"],
                    "metadata_filter": "author = \"Robert Graves\""
                }
            }]
        }' 2> /dev/null > response.json

cat response.json

metadata_filter के लिए, सूची फ़िल्टर सिंटैक्स लागू करने के बारे में दिशा-निर्देश यहां दिए गए हैं: google.aip.dev/160

उद्धरण

फ़ाइल खोज की सुविधा का इस्तेमाल करने पर, मॉडल के जवाब में उद्धरण शामिल हो सकते हैं. इनमें यह जानकारी होती है कि जवाब जनरेट करने के लिए, अपलोड किए गए दस्तावेज़ों के किन हिस्सों का इस्तेमाल किया गया है. इससे तथ्यों की जांच और पुष्टि करने में मदद मिलती है.

जवाब के grounding_metadata एट्रिब्यूट के ज़रिए, उद्धरण की जानकारी ऐक्सेस की जा सकती है.

Python

print(response.candidates[0].grounding_metadata)

JavaScript

console.log(JSON.stringify(response.candidates?.[0]?.groundingMetadata, null, 2));

इन मॉडल के साथ काम करता है

फ़ाइल खोजने की सुविधा, इन मॉडल के साथ काम करती है:

इस्तेमाल किए जा सकने वाले फ़ाइल टाइप

फ़ाइल खोजने की सुविधा, कई तरह के फ़ाइल फ़ॉर्मैट के साथ काम करती है. इनकी जानकारी यहां दी गई है.

ऐप्लिकेशन फ़ाइल के टाइप

  • application/dart
  • application/ecmascript
  • application/json
  • application/ms-java
  • application/msword
  • application/pdf
  • application/sql
  • application/typescript
  • application/vnd.curl
  • application/vnd.dart
  • application/vnd.ibm.secure-container
  • application/vnd.jupyter
  • application/vnd.ms-excel
  • application/vnd.oasis.opendocument.text
  • application/vnd.openxmlformats-officedocument.presentationml.presentation
  • application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
  • application/vnd.openxmlformats-officedocument.wordprocessingml.document
  • application/vnd.openxmlformats-officedocument.wordprocessingml.template
  • application/x-csh
  • application/x-hwp
  • application/x-hwp-v5
  • application/x-latex
  • application/x-php
  • application/x-powershell
  • application/x-sh
  • application/x-shellscript
  • application/x-tex
  • application/x-zsh
  • application/xml
  • application/zip

टेक्स्ट फ़ाइल के टाइप

  • text/1d-interleaved-parityfec
  • text/RED
  • text/SGML
  • text/cache-manifest
  • text/calendar
  • text/cql
  • text/cql-extension
  • text/cql-identifier
  • text/css
  • text/csv
  • text/csv-schema
  • text/dns
  • text/encaprtp
  • text/enriched
  • text/example
  • text/fhirpath
  • text/flexfec
  • text/fwdred
  • text/gff3
  • text/grammar-ref-list
  • text/hl7v2
  • text/html
  • text/javascript
  • text/jcr-cnd
  • text/jsx
  • text/markdown
  • text/mizar
  • text/n3
  • text/parameters
  • text/parityfec
  • text/php
  • text/plain
  • text/provenance-notation
  • text/prs.fallenstein.rst
  • text/prs.lines.tag
  • text/prs.prop.logic
  • text/raptorfec
  • text/rfc822-headers
  • text/rtf
  • text/rtp-enc-aescm128
  • text/rtploopback
  • text/rtx
  • text/sgml
  • text/shaclc
  • text/shex
  • text/spdx
  • text/strings
  • text/t140
  • text/tab-separated-values
  • text/texmacs
  • text/troff
  • text/tsv
  • text/tsx
  • text/turtle
  • text/ulpfec
  • text/uri-list
  • text/vcard
  • text/vnd.DMClientScript
  • text/vnd.IPTC.NITF
  • text/vnd.IPTC.NewsML
  • text/vnd.a
  • text/vnd.abc
  • text/vnd.ascii-art
  • text/vnd.curl
  • text/vnd.debian.copyright
  • text/vnd.dvb.subtitle
  • text/vnd.esmertec.theme-descriptor
  • text/vnd.exchangeable
  • text/vnd.familysearch.gedcom
  • text/vnd.ficlab.flt
  • text/vnd.fly
  • text/vnd.fmi.flexstor
  • text/vnd.gml
  • text/vnd.graphviz
  • text/vnd.hans
  • text/vnd.hgl
  • text/vnd.in3d.3dml
  • text/vnd.in3d.spot
  • text/vnd.latex-z
  • text/vnd.motorola.reflex
  • text/vnd.ms-mediapackage
  • text/vnd.net2phone.commcenter.command
  • text/vnd.radisys.msml-basic-layout
  • text/vnd.senx.warpscript
  • text/vnd.sosi
  • text/vnd.sun.j2me.app-descriptor
  • text/vnd.trolltech.linguist
  • text/vnd.wap.si
  • text/vnd.wap.sl
  • text/vnd.wap.wml
  • text/vnd.wap.wmlscript
  • text/vtt
  • text/wgsl
  • text/x-asm
  • text/x-bibtex
  • text/x-boo
  • text/x-c
  • text/x-c++hdr
  • text/x-c++src
  • text/x-cassandra
  • text/x-chdr
  • text/x-coffeescript
  • text/x-component
  • text/x-csh
  • text/x-csharp
  • text/x-csrc
  • text/x-cuda
  • text/x-d
  • text/x-diff
  • text/x-dsrc
  • text/x-emacs-lisp
  • text/x-erlang
  • text/x-gff3
  • text/x-go
  • text/x-haskell
  • text/x-java
  • text/x-java-properties
  • text/x-java-source
  • text/x-kotlin
  • text/x-lilypond
  • text/x-lisp
  • text/x-literate-haskell
  • text/x-lua
  • text/x-moc
  • text/x-objcsrc
  • text/x-pascal
  • text/x-pcs-gcd
  • text/x-perl
  • text/x-perl-script
  • text/x-python
  • text/x-python-script
  • text/x-r-markdown
  • text/x-rsrc
  • text/x-rst
  • text/x-ruby-script
  • text/x-rust
  • text/x-sass
  • text/x-scala
  • text/x-scheme
  • text/x-script.python
  • text/x-scss
  • text/x-setext
  • text/x-sfv
  • text/x-sh
  • text/x-siesta
  • text/x-sos
  • text/x-sql
  • text/x-swift
  • text/x-tcl
  • text/x-tex
  • text/x-vbasic
  • text/x-vcalendar
  • text/xml
  • text/xml-dtd
  • text/xml-external-parsed-entity
  • text/yaml

तय सीमाएं

File Search API की ये सीमाएं हैं, ताकि सेवा को बेहतर तरीके से उपलब्ध कराया जा सके:

  • फ़ाइल का ज़्यादा से ज़्यादा साइज़ / हर दस्तावेज़ के लिए तय सीमा: 100 एमबी
  • प्रोजेक्ट फ़ाइल खोज के लिए उपलब्ध स्टोरेज का कुल साइज़ (उपयोगकर्ता के टियर के आधार पर):
    • मुफ़्त: 1 जीबी
    • टियर 1: 10 जीबी
    • दूसरा टियर: 100 जीबी
    • टियर 3: 1 टीबी
  • सुझाव: हर फ़ाइल खोज स्टोर का साइज़ 20 जीबी से कम रखें, ताकि फ़ाइलें खोजने में कम समय लगे.

कीमत

  • डेवलपर से इंडेक्सिंग के समय, एम्बेडिंग के लिए शुल्क लिया जाता है. यह शुल्क, एम्बेडिंग की मौजूदा कीमत के आधार पर लिया जाता है. फ़िलहाल, यह कीमत 10 लाख टोकन के लिए 0.15 डॉलर है.
  • स्टोरेज की सुविधा बिना किसी शुल्क के मिलती है.
  • क्वेरी टाइम एम्बेडिंग की सुविधा बिना किसी शुल्क के उपलब्ध है.
  • फ़ेच किए गए दस्तावेज़ टोकन के लिए, सामान्य कॉन्टेक्स्ट टोकन के तौर पर शुल्क लिया जाता है.

आगे क्या करना है