spring-projects / spring-projects/spring-ai

SimpleVectorStore: expose JSON String serialization features

Open
#2,181 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

SimpleVectorStore now saves store to file with JSON string format. But logic to convert store to JSON string is private and not exposed.

I have a requirement to save small SimpleVectorStore into a database table column as a JSON string, instead of storing it into a file. So, I create a new class, and copy JSON format logic from SimpleVectorStore.

Current Behavior

Currently, here is what I'm doing:

class MySimpleVectorStore extends SimpleVectorStore {
  public String toJSONString() {
    // copy what getVectorDbAsJson() from SimpleVectorStore
  }

  public void fromJSONString(String jsonString) {
    // copy logic from load(File file), with ObjectMapper.readValue(jsonString, typeRef) instead of file.
  }
}

This approach has multiple issues:

  • Recreating mutable internal states for parent class SimpleVectorStore
  • Duplicated code logic

Context

Propose to expose JSON string related feature out of SimpleVectorStore. Something like:

class SimpleVectorStore {
    public String toJSONString() {
      return this.getVectorDbAsJson();
    }

    public void fromJSONString(String jsonString) {
      // very similar to save(File) method
      // may consider refactor save(File) feature together with this one.
    }
}

To have this design:

  • The serialized JSON string format, shared with today's file content format. So it's compatibility related concerns should be discussed there.

The proposed design, will open up creative ways to persistent and transfer small VectorStores:

  • as JSON string and save into database if VectorStore is small
  • as a binary or string value stored in Redis
  • persist via socket

Alternative aproaches:

  • First save to file and then read from file to database

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at SimpleVectorStore and inspect getVectorDbAsJson(), save(File), and load(File) to understand the existing JSON file format and shared state handling. Define string serialization and deserialization without duplicating logic, while preserving compatibility with today’s file content format; verify the existing file behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.