spring-ai-examples
spring-ai-examples copied to clipboard
How to apply this to JSON
https://github.com/habuma/spring-ai-examples/blob/9dc0727db5843a5bde9dc3169cc939112a480b75/vector-store-loader/src/main/java/com/example/vectorstoreloader/VectorStoreLoaderApplication.java#L58
Hey Craig, I'm trying to figure out how to apply this to my json api doc. This is my first time using the TokenTextSplitter. I guess I'm worried that it is sort of randomly splitting the text by length when the json has some very clear structure that would probably make more sense for splitting.
Can you point me in the right direction?
@Component
public class ReferenceDocsLoader {
private static final Logger log = LoggerFactory.getLogger(ReferenceDocsLoader.class);
private final JdbcClient jdbcClient;
private final VectorStore vectorStore;
@Value("classpath:/docs/api-docs.json")
private Resource apiDocs;
public ReferenceDocsLoader(JdbcClient jdbcClient, VectorStore vectorStore) {
this.jdbcClient = jdbcClient;
this.vectorStore = vectorStore;
}
@PostConstruct
public void init() {
Integer count = jdbcClient.sql("select count(*) from vector_store")
.query(Integer.class)
.single();
log.info("Current count of the Vector Store: {}", count);
if (count == 0) {
try {
String json = Files.readString(Paths.get(apiDocs.getURI()));
Document doc = new Document(json);
List<Document> subDocs = new TokenTextSplitter().apply(List.of(doc));
vectorStore.accept(subDocs);
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
}
}