Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 82 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ The **GenAIApp** library is a Google Apps Script library designed for creating,
- [Creating a Function](#creating-a-function)
- [Configuring Parameters](#configuring-parameters)
- [VectorStoreObject Class](#vectorstoreobject-class)
- [Create a Vector Store](#create-a-vector-store)
- [Upload Documents](#upload-documents)
- [Use a Vector Store in a Chat](#use-a-vector-store-in-a-chat)
- [Optional Controls](#optional-controls)
- [Retrieving Knowledge from an OpenAI Vector Store](#retrieving-knowledge-from-an-openai-vector-store)
- [Examples](#examples)
- [Example 1: Send a Prompt and Get Completion](#example-1--send-a-prompt-and-get-completion)
Expand Down Expand Up @@ -256,16 +260,83 @@ functionObject.addParameter("rating", "number", "The minimum rating of movies to

## VectorStoreObject Class

### Retrieving Knowledge from an OpenAI Vector Store
The `VectorStoreObject` class lets you create and use vector stores for Retrieval Augmented Generation (RAG).
Vector stores allow the model to retrieve relevant information from your own documents during a chat.

Retrieve contextual information from a specific OpenAI vector search :
GenAIApp supports:

```js
const vectorStoreObject = GenAIApp.newVectorStore()
.initializeFromId("your-vector-store-id");
chat.addVectorStore(vectorStoreObject);
- OpenAI vector stores

- Google Vertex AI RAG

### Create a Vector Store

By default, GenAIApp creates an OpenAI vector store.

```javascript
GenAIApp.setOpenAIAPIKey(OPEN_AI_API_KEY);

const vectorStore = GenAIApp.newVectorStore()
.setName("Support knowledge base")
.createVectorStore();

const vectorStoreId = vectorStore.getId();
```

To use Google Vertex AI RAG instead, specify the provider and a GCS bucket:

```javascript
GenAIApp.setGeminiAuth("my-gcp-project-id", "europe-west4");

// RAG endpoints use a dedicated region (may differ from Gemini auth region)
GenAIApp.setRagRegion("europe-west4");

const vectorStore = GenAIApp.newVectorStore("google")
.setName("Product documentation")
.setBucketName("gs://my-rag-bucket")
.createVectorStore();
```

> ⚠️ **Warning:** `setGeminiAuth()` configures authentication and region for Gemini
> model calls, while `setRagRegion()` controls the region used for Vertex AI RAG
> operations. Since RAG is not available in all regions, these two values may
> differ and should both be set explicitly when using Google Vertex AI RAG.


### Upload Documents

Documents are provided as `Blob` objects and are automatically chunked and embedded.

```javascript
const blob = /* any Blob (PDF, text, image, etc.) */;
vectorStore.uploadAndAttachFile(blob);
```

You can also upload multiple documents at once:

```javascript
vectorStore.uploadAndAttachFiles([blob1, blob2]);
```

### Use a Vector Store in a Chat

```javascript
const chat = GenAIApp.newChat();

chat
.addMessage("How do I reset my password?")
.addVectorStores(vectorStoreId);

const answer = chat.run();
Logger.log(answer);
```

### Optional Controls

```javascript
chat.setMaxChunks(5); // Limit retrieved chunks
chat.onlyReturnChunks(true); // Return raw chunks instead of a text answer
```
To find out more : [https://platform.openai.com/docs/api-reference/vector_stores/search](https://platform.openai.com/docs/api-reference/vector_stores/search)

## Examples

Expand Down Expand Up @@ -460,15 +531,18 @@ A `FunctionObject` represents a function that can be called by the chat.

### Vector Store Object

A `VectorStoreObject` represents an OpenAI vector store.
A `VectorStoreObject` represents a vector store (OpenAI or Google Vertex AI RAG).

- `setName(newName)`: Set the vector store name.
- `setDescription(newDesc)`: Set the description.
- `setChunkingStrategy(maxChunkSize, chunkOverlap)`: Configure chunking before uploads.
- `setBucketName(bucketAddress)`: Set the Google Cloud Storage bucket (Google RAG only).
- `createVectorStore()`: Create the vector store.
- `initializeFromId(vectorStoreId)`: Initialize from an existing vector store ID.
- `getId()`: Get the vector store ID.
- `getProvider()`: Get the underlying provider (`"openai"` or `"google"`).
- `uploadAndAttachFile(blob, attributes)`: Upload a file and attach it to the store.
- `uploadAndAttachFiles(blobs, attributesList)`: Upload and attach multiple files.
- `listFiles()`: List files attached to the store.
- `deleteFile(fileId)`: Delete a file from the store.
- `deleteVectorStore()`: Delete the vector store.
Expand Down
Loading