Spring AI similarity search fails with Weaviate vector store

93 Views Asked by At

I am using Spring AI with Azure open AI for the embeddings and text generation. I have a Weaviate vector store running in docker locally. My documents have been successfully embedded and saved to the vector store. The problem comes when I implement the code for a similarity search, here is the code ->

public List<Document> similaritySearch() { return vectorStore.similaritySearch( SearchRequest .query("Spring") .withTopK(1)); }

The application build fails with the following error message ->

error: incompatible types: SearchRequest cannot be converted to String .withTopK(1));

I have followed the spring docs exactly so I'm at a loss as to whats wrong. Interestingly if I remove the line -> .withTopK(1)); it still fails on the line -> .query("Spring") and if I add .toString after the line .withTopK(1)); the application runs but all data is returned rather than only the most similar.

Perhaps there is something wrong with my dependencies, here they are from the gradle file ->

dependencies { implementation 'org.springframework.experimental.ai:spring-ai-azure-openai-spring-boot-starter:0.2.0-SNAPSHOT' implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.ai:spring-ai-weaviate-store:0.8.0-SNAPSHOT' implementation 'io.weaviate:client:4.5.1' implementation 'org.flywaydb:flyway-core' implementation 'org.flywaydb:flyway-mysql' compileOnly 'org.projectlombok:lombok' runtimeOnly 'org.mariadb.jdbc:mariadb-java-client' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' }

Any idea why this is failing?

I tried using toString and I played around with the dependencies as best I could. I was expecting only one similar document to be returned but the all are.

0

There are 0 best solutions below