or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

auth-tokens.mdbatch.mdcaching.mdchat.mdclient.mdcontent-generation.mdembeddings.mdfile-search-stores.mdfiles.mdfunction-calling.mdimage-generation.mdindex.mdlive.mdmcp.mdmodels.mdoperations.mdtuning.mdvideo-generation.md

file-search-stores.mddocs/

0

# File Search Stores

1

2

File Search Stores provide document management and search capabilities for the Gemini API. A FileSearchStore acts as a container for documents that can be searched and retrieved during generation. The FileSearchStores class includes a nested Documents class for managing individual documents within a store.

3

4

**Note**: File Search Store functionality is only available in the Gemini Developer API, not in Vertex AI.

5

6

## Capabilities

7

8

### Create File Search Store

9

10

Creates a new FileSearchStore to hold documents for search operations.

11

12

```typescript { .api }

13

/**

14

* Creates a File Search Store

15

* @param params - Parameters for creating the file search store

16

* @returns Promise resolving to the created FileSearchStore

17

*/

18

function create(params: CreateFileSearchStoreParameters): Promise<FileSearchStore>;

19

20

interface CreateFileSearchStoreParameters {

21

config?: CreateFileSearchStoreConfig;

22

}

23

24

interface CreateFileSearchStoreConfig {

25

displayName?: string;

26

httpOptions?: HttpOptions;

27

abortSignal?: AbortSignal;

28

}

29

30

interface FileSearchStore {

31

name?: string;

32

displayName?: string;

33

createTime?: string;

34

updateTime?: string;

35

}

36

```

37

38

**Usage Example:**

39

40

```typescript

41

import { GoogleGenAI } from '@google/genai';

42

43

const client = new GoogleGenAI({ apiKey: 'YOUR_API_KEY' });

44

45

const store = await client.fileSearchStores.create({

46

config: {

47

displayName: 'My Document Store'

48

}

49

});

50

51

console.log('Created store:', store.name);

52

```

53

54

### List File Search Stores

55

56

Lists all FileSearchStores owned by the user with pagination support.

57

58

```typescript { .api }

59

/**

60

* Lists file search stores

61

* @param params - Optional parameters for pagination

62

* @returns Promise resolving to a Pager of FileSearchStores

63

*/

64

function list(params?: ListFileSearchStoresParameters): Promise<Pager<FileSearchStore>>;

65

66

interface ListFileSearchStoresParameters {

67

config?: ListFileSearchStoresConfig;

68

}

69

70

interface ListFileSearchStoresConfig {

71

pageSize?: number;

72

pageToken?: string;

73

httpOptions?: HttpOptions;

74

abortSignal?: AbortSignal;

75

}

76

```

77

78

**Usage Example:**

79

80

```typescript

81

const stores = await client.fileSearchStores.list({

82

config: { pageSize: 10 }

83

});

84

85

for await (const store of stores) {

86

console.log('Store:', store.name, store.displayName);

87

}

88

```

89

90

### Get File Search Store

91

92

Retrieves a specific FileSearchStore by name.

93

94

```typescript { .api }

95

/**

96

* Gets a File Search Store

97

* @param params - Parameters specifying which store to retrieve

98

* @returns Promise resolving to the FileSearchStore

99

*/

100

function get(params: GetFileSearchStoreParameters): Promise<FileSearchStore>;

101

102

interface GetFileSearchStoreParameters {

103

name: string;

104

config?: GetFileSearchStoreConfig;

105

}

106

107

interface GetFileSearchStoreConfig {

108

httpOptions?: HttpOptions;

109

abortSignal?: AbortSignal;

110

}

111

```

112

113

**Usage Example:**

114

115

```typescript

116

const store = await client.fileSearchStores.get({

117

name: 'fileSearchStores/abc123'

118

});

119

120

console.log('Store details:', store);

121

```

122

123

### Delete File Search Store

124

125

Deletes a FileSearchStore and all its associated documents.

126

127

```typescript { .api }

128

/**

129

* Deletes a File Search Store

130

* @param params - Parameters specifying which store to delete

131

* @returns Promise resolving when deletion is complete

132

*/

133

function delete(params: DeleteFileSearchStoreParameters): Promise<void>;

134

135

interface DeleteFileSearchStoreParameters {

136

name: string;

137

config?: DeleteFileSearchStoreConfig;

138

}

139

140

interface DeleteFileSearchStoreConfig {

141

httpOptions?: HttpOptions;

142

abortSignal?: AbortSignal;

143

}

144

```

145

146

**Usage Example:**

147

148

```typescript

149

await client.fileSearchStores.delete({

150

name: 'fileSearchStores/abc123'

151

});

152

153

console.log('Store deleted successfully');

154

```

155

156

### Upload File to File Search Store

157

158

Uploads a file asynchronously to a FileSearchStore, returning a long-running operation. Supported upload sources vary by platform:

159

- Node.js: File path (string) or Blob object

160

- Browser: Blob object (e.g., File)

161

162

```typescript { .api }

163

/**

164

* Uploads a file asynchronously to a FileSearchStore

165

* @param params - Upload parameters including file and destination store

166

* @returns Promise resolving to an UploadToFileSearchStoreOperation

167

* @throws Error if called on a Vertex AI client

168

* @throws Error if mimeType cannot be inferred

169

*/

170

function uploadToFileSearchStore(

171

params: UploadToFileSearchStoreParameters

172

): Promise<UploadToFileSearchStoreOperation>;

173

174

interface UploadToFileSearchStoreParameters {

175

fileSearchStoreName: string;

176

file: string | Blob;

177

config?: UploadToFileSearchStoreConfig;

178

}

179

180

interface UploadToFileSearchStoreConfig {

181

mimeType?: string;

182

displayName?: string;

183

httpOptions?: HttpOptions;

184

abortSignal?: AbortSignal;

185

}

186

187

interface UploadToFileSearchStoreOperation {

188

name?: string;

189

done?: boolean;

190

response?: UploadToFileSearchStoreResponse;

191

error?: Status;

192

metadata?: Record<string, unknown>;

193

}

194

195

interface UploadToFileSearchStoreResponse {

196

document?: Document;

197

}

198

```

199

200

**Usage Example:**

201

202

```typescript

203

// Upload from file path (Node.js)

204

const operation = await client.fileSearchStores.uploadToFileSearchStore({

205

fileSearchStoreName: 'fileSearchStores/abc123',

206

file: '/path/to/document.pdf',

207

config: {

208

mimeType: 'application/pdf',

209

displayName: 'Important Document'

210

}

211

});

212

213

console.log('Upload operation:', operation.name);

214

215

// Check operation status

216

if (operation.done) {

217

console.log('Document uploaded:', operation.response?.document?.name);

218

}

219

```

220

221

### Import File to File Search Store

222

223

Imports a file from the File Service to a FileSearchStore as a long-running operation. This method allows you to add files that have already been uploaded via the Files API to a FileSearchStore for search capabilities.

224

225

```typescript { .api }

226

/**

227

* Imports a File from File Service to a FileSearchStore

228

* @param params - Import parameters including source file and destination store

229

* @returns Promise resolving to an ImportFileOperation

230

* @throws Error if called on a Vertex AI client

231

*/

232

function importFile(params: ImportFileParameters): Promise<ImportFileOperation>;

233

234

interface ImportFileParameters {

235

file_search_store_name: string;

236

file_name: string;

237

config?: ImportFileConfig;

238

}

239

240

interface ImportFileConfig {

241

httpOptions?: HttpOptions;

242

abortSignal?: AbortSignal;

243

}

244

245

interface ImportFileOperation {

246

name?: string;

247

done?: boolean;

248

response?: ImportFileResponse;

249

error?: Status;

250

metadata?: Record<string, unknown>;

251

}

252

253

interface ImportFileResponse {

254

document?: Document;

255

}

256

```

257

258

**Usage Example:**

259

260

```typescript

261

// First, upload a file using the Files API

262

const uploadedFile = await client.files.upload({

263

file: '/path/to/document.pdf'

264

});

265

266

// Then import it into a FileSearchStore

267

const operation = await client.fileSearchStores.importFile({

268

file_search_store_name: 'fileSearchStores/abc123',

269

file_name: uploadedFile.name

270

});

271

272

console.log('Import operation:', operation.name);

273

```

274

275

## Document Management

276

277

The FileSearchStores class exposes a nested `documents` property that provides methods for managing individual documents within a store.

278

279

### Documents Class

280

281

Access document management operations via `client.fileSearchStores.documents`.

282

283

```typescript { .api }

284

interface FileSearchStores {

285

readonly documents: Documents;

286

}

287

288

class Documents {

289

list(params: ListDocumentsParameters): Promise<Pager<Document>>;

290

get(params: GetDocumentParameters): Promise<Document>;

291

delete(params: DeleteDocumentParameters): Promise<void>;

292

}

293

```

294

295

### List Documents

296

297

Lists all documents in a FileSearchStore with pagination support.

298

299

```typescript { .api }

300

/**

301

* Lists documents in a FileSearchStore

302

* @param params - Parameters including the parent store name

303

* @returns Promise resolving to a Pager of Documents

304

*/

305

function list(params: ListDocumentsParameters): Promise<Pager<Document>>;

306

307

interface ListDocumentsParameters {

308

parent: string;

309

config?: ListDocumentsConfig;

310

}

311

312

interface ListDocumentsConfig {

313

pageSize?: number;

314

pageToken?: string;

315

httpOptions?: HttpOptions;

316

abortSignal?: AbortSignal;

317

}

318

319

interface Document {

320

name?: string;

321

displayName?: string;

322

mimeType?: string;

323

sizeBytes?: string;

324

createTime?: string;

325

updateTime?: string;

326

state?: DocumentState;

327

metadata?: Record<string, string>;

328

}

329

330

enum DocumentState {

331

DOCUMENT_STATE_UNSPECIFIED = 'DOCUMENT_STATE_UNSPECIFIED',

332

PROCESSING = 'PROCESSING',

333

ACTIVE = 'ACTIVE',

334

FAILED = 'FAILED'

335

}

336

```

337

338

**Usage Example:**

339

340

```typescript

341

const documents = await client.fileSearchStores.documents.list({

342

parent: 'fileSearchStores/abc123',

343

config: { pageSize: 20 }

344

});

345

346

for await (const document of documents) {

347

console.log('Document:', document.name, document.displayName, document.state);

348

}

349

```

350

351

### Get Document

352

353

Retrieves a specific document by name.

354

355

```typescript { .api }

356

/**

357

* Gets a Document

358

* @param params - Parameters specifying which document to retrieve

359

* @returns Promise resolving to the Document

360

*/

361

function get(params: GetDocumentParameters): Promise<Document>;

362

363

interface GetDocumentParameters {

364

name: string;

365

config?: GetDocumentConfig;

366

}

367

368

interface GetDocumentConfig {

369

httpOptions?: HttpOptions;

370

abortSignal?: AbortSignal;

371

}

372

```

373

374

**Usage Example:**

375

376

```typescript

377

const document = await client.fileSearchStores.documents.get({

378

name: 'fileSearchStores/abc123/documents/doc456'

379

});

380

381

console.log('Document:', document.displayName, document.mimeType, document.sizeBytes);

382

```

383

384

### Delete Document

385

386

Deletes a specific document from a FileSearchStore.

387

388

```typescript { .api }

389

/**

390

* Deletes a Document

391

* @param params - Parameters specifying which document to delete

392

* @returns Promise resolving when deletion is complete

393

*/

394

function delete(params: DeleteDocumentParameters): Promise<void>;

395

396

interface DeleteDocumentParameters {

397

name: string;

398

config?: DeleteDocumentConfig;

399

}

400

401

interface DeleteDocumentConfig {

402

httpOptions?: HttpOptions;

403

abortSignal?: AbortSignal;

404

}

405

```

406

407

**Usage Example:**

408

409

```typescript

410

await client.fileSearchStores.documents.delete({

411

name: 'fileSearchStores/abc123/documents/doc456'

412

});

413

414

console.log('Document deleted successfully');

415

```

416

417

## Using File Search Stores with Generation

418

419

File Search Stores can be used with the FileSearch tool during content generation to provide search capabilities over your documents.

420

421

```typescript

422

import { GoogleGenAI } from '@google/genai';

423

424

const client = new GoogleGenAI({ apiKey: 'YOUR_API_KEY' });

425

426

// Create a file search store and upload documents

427

const store = await client.fileSearchStores.create({

428

config: { displayName: 'Product Documentation' }

429

});

430

431

await client.fileSearchStores.uploadToFileSearchStore({

432

fileSearchStoreName: store.name,

433

file: '/path/to/product-guide.pdf'

434

});

435

436

// Use the file search store in generation

437

const response = await client.models.generateContent({

438

model: 'gemini-2.0-flash',

439

contents: 'What are the key features mentioned in the product guide?',

440

config: {

441

tools: [{

442

fileSearch: {

443

fileSearchStore: store.name

444

}

445

}]

446

}

447

});

448

449

console.log(response.text);

450

```

451

452

## Type Definitions

453

454

```typescript { .api }

455

interface Status {

456

code?: number;

457

message?: string;

458

details?: Array<Record<string, unknown>>;

459

}

460

461

interface ListDocumentsResponse {

462

documents?: Document[];

463

nextPageToken?: string;

464

}

465

466

interface ListFileSearchStoresResponse {

467

fileSearchStores?: FileSearchStore[];

468

nextPageToken?: string;

469

}

470

```

471