You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Therefore i would expect, that setting the property spring.ai.ollama.embedding.options.keep-alive=-1 would keep it in memory.
But in reality, the org.springframework.ai.ollama.OllamaEmbeddingModel.DurationParser uses the following regex: (\d+)(ms|s|m|h). The value of -1 violates it in two ways:
a negative value is generally not allowed
a value without a duration is not allowed
Environment spring-ai-ollama-1.0.0-SNAPSHOT
Steps to reproduce
Set the property to spring.ai.ollama.embedding.options.keep-alive=-1 and make a embedding request.
Expected behavior
The model is kept in memory and no exception is raised.
Minimal Complete Reproducible example
The following test class is written in Groovy using the Spock framework.
Based on the documentation of the Ollama as state above, i would expect that all of these tests would pass, but only the first one passes. org.spockframework:spock-core:2.4-M1-groovy-4.0
importorg.springframework.ai.ollama.OllamaEmbeddingModelimportspock.lang.SpecificationclassOllamaEmbeddingModelDurationParserSpecextendsSpecification {
OllamaEmbeddingModel.DurationParser parser =newOllamaEmbeddingModel.DurationParser()
def"the parser parses a positive number with duration"() {
when:
def result = parser.parse("1m")
then:
noExceptionThrown()
result !=null
}
def"the parser parses a negative number with duration"() {
when:
def result = parser.parse("-1m")
then:
noExceptionThrown()
result !=null
}
def"the parser parses a positive number without duration"() {
when:
def result = parser.parse("1")
then:
noExceptionThrown()
result !=null
}
def"the parser parses a negative number without duration"() {
when:
def result = parser.parse("-1")
then:
noExceptionThrown()
result !=null
}
}
Output from the test (Exceptions only):
Expected no exception to be thrown, but got 'java.lang.IllegalArgumentException'
at spock.lang.Specification.noExceptionThrown(Specification.java:118)
at com.pineapple.netnix.OllamaEmbeddingModelDurationParserSpec.the parser parses a negative number with duration(Test.groovy:21)
Caused by: java.lang.IllegalArgumentException: Invalid duration format: -1m
at org.springframework.ai.ollama.OllamaEmbeddingModel$DurationParser.parse(OllamaEmbeddingModel.java:214)
at com.pineapple.netnix.OllamaEmbeddingModelDurationParserSpec.the parser parses a negative number with duration(Test.groovy:19)
Expected no exception to be thrown, but got 'java.lang.IllegalArgumentException'
at spock.lang.Specification.noExceptionThrown(Specification.java:118)
at com.pineapple.netnix.OllamaEmbeddingModelDurationParserSpec.the parser parses a positive number without duration(Test.groovy:29)
Caused by: java.lang.IllegalArgumentException: Invalid duration format: 1
at org.springframework.ai.ollama.OllamaEmbeddingModel$DurationParser.parse(OllamaEmbeddingModel.java:214)
at com.pineapple.netnix.OllamaEmbeddingModelDurationParserSpec.the parser parses a positive number without duration(Test.groovy:27)
Expected no exception to be thrown, but got 'java.lang.IllegalArgumentException'
at spock.lang.Specification.noExceptionThrown(Specification.java:118)
at com.pineapple.netnix.OllamaEmbeddingModelDurationParserSpec.the parser parses a negative number without duration(Test.groovy:37)
Caused by: java.lang.IllegalArgumentException: Invalid duration format: -1
at org.springframework.ai.ollama.OllamaEmbeddingModel$DurationParser.parse(OllamaEmbeddingModel.java:214)
at com.pineapple.netnix.OllamaEmbeddingModelDurationParserSpec.the parser parses a negative number without duration(Test.groovy:35)
Potential side discussion
I know this is not directly related to the bug, but maybe the name of the property might be misleading. Without reading the documentation, i would expect that spring.ai.ollama.embedding.options.keep-alive takes a boolean, defining if it should keep it in memory, or not. Of course it makes more sense to define a duration here, but in that case i would suggest a rename of the property to keep-alive-duration
The text was updated successfully, but these errors were encountered:
Bug description
In the documentation of Ollama ( https://github.com/ollama/ollama/blob/main/docs/faq.md#how-do-i-keep-a-model-loaded-in-memory-or-make-it-unload-immediately ) its clearly stated, that if i want a model to stay in memory, a negative value should be presented. Here the citation:
any negative number which will keep the model loaded in memory (e.g. -1 or "-1m")
Therefore i would expect, that setting the property
spring.ai.ollama.embedding.options.keep-alive=-1
would keep it in memory.But in reality, the
org.springframework.ai.ollama.OllamaEmbeddingModel.DurationParser
uses the following regex:(\d+)(ms|s|m|h)
. The value of-1
violates it in two ways:Environment
spring-ai-ollama-1.0.0-SNAPSHOT
Steps to reproduce
Set the property to
spring.ai.ollama.embedding.options.keep-alive=-1
and make a embedding request.Expected behavior
The model is kept in memory and no exception is raised.
Minimal Complete Reproducible example
The following test class is written in Groovy using the Spock framework.
Based on the documentation of the Ollama as state above, i would expect that all of these tests would pass, but only the first one passes.
org.spockframework:spock-core:2.4-M1-groovy-4.0
Output from the test (Exceptions only):
Potential side discussion
I know this is not directly related to the bug, but maybe the name of the property might be misleading. Without reading the documentation, i would expect that
spring.ai.ollama.embedding.options.keep-alive
takes a boolean, defining if it should keep it in memory, or not. Of course it makes more sense to define a duration here, but in that case i would suggest a rename of the property tokeep-alive-duration
The text was updated successfully, but these errors were encountered: