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
Bug description
I'm implementing vector similarity search using mongo atlas DB, using spring ai 1.0.0 stable version
vectorStore.similaritySearch(SearchRequest.builder().query(query).topK(5).build());
This code is failing with a class org.bson.types.ObjectId cannot be cast to class java.lang.String, when i tried to get the list of documents as described in the documentation this should be working without issues.
Adding the stack trace
java.lang.ClassCastException: class org.bson.types.ObjectId cannot be cast to class java.lang.String (org.bson.types.ObjectId is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap')
at org.bson.Document.getString(Document.java:308) ~[bson-5.2.1.jar:na]
at org.springframework.ai.vectorstore.mongodb.atlas.MongoDBAtlasVectorStore.mapMongoDocument(MongoDBAtlasVectorStore.java:243) ~[spring-ai-mongodb-atlas-store-1.0.0.jar:1.0.0]
at org.springframework.ai.vectorstore.mongodb.atlas.MongoDBAtlasVectorStore.lambda$doSimilaritySearch$1(MongoDBAtlasVectorStore.java:317) ~[spring-ai-mongodb-atlas-store-1.0.0.jar:1.0.0]
Potential solution could be to get the ID as an hexadecimal string value directly as there is no direct conversion from the mongo bson document.
String id = mongoDocument.getObjectId(ID_FIELD_NAME).toHexString();