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

SimpleVectorStore: expose JSON String serialization features #2181

Open
dopsun opened this issue Feb 6, 2025 · 0 comments
Open

SimpleVectorStore: expose JSON String serialization features #2181

dopsun opened this issue Feb 6, 2025 · 0 comments

Comments

@dopsun
Copy link

dopsun commented Feb 6, 2025

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
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