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

How to apply this to JSON #3

Open
LiveNathan opened this issue Jun 6, 2024 · 0 comments
Open

How to apply this to JSON #3

LiveNathan opened this issue Jun 6, 2024 · 0 comments

Comments

@LiveNathan
Copy link

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);
            }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant