Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto truncate for vertex embedding is broken by TokenCountBatchingStrategy #1831

Open
GregoireW opened this issue Nov 26, 2024 · 2 comments
Open
Assignees
Labels
bug Something isn't working vertex
Milestone

Comments

@GregoireW
Copy link

Bug description

I try to use vertex embedding and did test big document. I did set the auto-truncate to true.
This correspond to this options:

But I got an exception from TokenCountBatchingStrategy (

)

What to do in this situation ?

Environment

Spring AI 1.0.0-M4 / jdk21

Steps to reproduce

Use vertex embedding with the "auto truncate" option, and test with a large payload.

Expected behavior

Success or at least some way in the documentation to make it works.

Minimal Complete Reproducible example

var document = new Document("go ".repeat(50000));
vectorStore.add(List.of(document));

@sobychacko sobychacko added this to the 1.0.0-M5 milestone Nov 27, 2024
@sobychacko sobychacko self-assigned this Nov 27, 2024
@sobychacko
Copy link
Contributor

@GregoireW, Which vector store are you using? To fix this issue, you need to provide a custom BatchingStrategy ben in your application. The default TokenCountBatchingStrategy implementation uses the default context-window size set by openai - 8191. You need to adjust the max token size when using different embedding models. Here is an example of overriding this bean:

@Bean
@ConditionalOnMissingBean(BatchingStrategy.class)
    BatchingStrategy chromaBatchingStrategy() {
      return new TokenCountBatchingStrategy(EncodingType.CL100K_BASE, maxInputTokenCount, 0.1);
}

See the javadoc on ToeknCountBatchingStrategy for more details: https://github.com/spring-projects/spring-ai/blob/main/spring-ai-core/src/main/java/org/springframework/ai/embedding/TokenCountBatchingStrategy.java

@GregoireW
Copy link
Author

I use pgVector storage.

If the way is to create a BatchingStragery, I guess the documentation on the auto-truncate feature should be explicit.

Or it is still a work in progress to make it work with embedding models in which case the the case would be corrected later.

I let you close this issue or set a "todo something" if you want.

@markpollack markpollack added bug Something isn't working vertex labels Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working vertex
Projects
None yet
Development

No branches or pull requests

3 participants