Skip to content

Commit

Permalink
indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinthecheung committed May 3, 2024
1 parent d00c8e2 commit 484de44
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions docs/plugins/firebase.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const yourRetrieverRef = defineFirestoreRetriever({
contentField: 'yourDataChunks',
vectorField: 'embedding',
embedder: textEmbeddingGecko,
distanceMeasure: 'COSINE', // 'EUCLIDEAN', 'DOT_PRODUCT', or 'COSINE' (default)
});
```

Expand All @@ -97,8 +98,39 @@ const docs = await retrieve({
For indexing, use an embedding generator along with the Admin SDK:

```js
import { initializeApp } from "firebase-admin";
import { getFirestore } from "firebase-admin/firestore";
import { textEmbeddingGecko } from '@genkit-ai/vertexai';
import { embed } from '@genkit-ai/ai/embedder';

const app = initializeApp();
const firestore = getFirestore(app);

const indexConfig = {
collection: "yourCollection",
contentField: "yourDataChunks",
vectorField: "embedding",
embedder: textEmbeddingGecko,
}

async function indexToFirestore(content) {
const embedding = await embed({
embedder: indexConfig.embedder,
content,
});
await firestore.collection(indexConfig.collection).add({
[indexConfig.vectorField]: embedding,
[indexConfig.contentField]: content,
});
}
```

Firestore depends on indices to provide fast and efficient querying on
collections. The prior example requires the `embedding` field to be indexed to
work. To do so, invoke the function and Firestore will throw an error with a
command to create an index. Execute that command and your index should be ready
to use.

See the [Retrieval-augmented generation](../rag.md) page for a general
discussion on indexers and retrievers.

Expand Down

0 comments on commit 484de44

Please sign in to comment.