Skip to content

SimpleVectorStore: expose JSON String serialization features #2181

Open
@dopsun

Description

@dopsun

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions