Skip to content

Commit

Permalink
feat: Add support for reduced output dimensionality in GoogleGenerati…
Browse files Browse the repository at this point in the history
…veAIEmbeddings (#544)
  • Loading branch information
davidmigloz authored Aug 31, 2024
1 parent e916ad3 commit d588070
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ class GoogleGenerativeAIEmbeddings implements Embeddings {

/// The number of dimensions the resulting output embeddings should have.
/// Only supported in `text-embedding-004` and later models.
/// TODO https://github.com/google-gemini/generative-ai-dart/pull/149
int? dimensions;

/// The maximum number of documents to embed in a single request.
Expand Down Expand Up @@ -168,7 +167,7 @@ class GoogleGenerativeAIEmbeddings implements Embeddings {
Content.text(doc.pageContent),
taskType: TaskType.retrievalDocument,
title: doc.metadata[docTitleKey],
// outputDimensionality: dimensions, TODO
outputDimensionality: dimensions,
);
}).toList(growable: false),
);
Expand All @@ -187,7 +186,7 @@ class GoogleGenerativeAIEmbeddings implements Embeddings {
final data = await _googleAiClient.embedContent(
Content.text(query),
taskType: TaskType.retrievalQuery,
// outputDimensionality: dimensions, TODO
outputDimensionality: dimensions,
);
return data.embedding.values;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ void main() {
expect(res[1].length, 768);
});

// TODO https://github.com/google-gemini/generative-ai-dart/pull/149
test('Test shortening embeddings', skip: true, () async {
test('Test shortening embeddings', () async {
embeddings.dimensions = 256;
final res = await embeddings.embedQuery('Hello world');
expect(res.length, 256);
Expand Down

0 comments on commit d588070

Please sign in to comment.