Skip to content

Navigation Menu

Sign in
Sign up

[ISSUE-851] implemented VectorStore and VectorStoreMetadata interfaces with validation and persistence - #855

Open
Sumit2342 wants to merge 2 commits into
apache:master from
Sumit2342:feature/issue-851-vector-store-spi
Open

[ISSUE-851] implemented VectorStore and VectorStoreMetadata interfaces with validation and persistence #855
Sumit2342 wants to merge 2 commits into
apache:master from
Sumit2342:feature/issue-851-vector-store-spi

Conversation

@Sumit2342

@Sumit2342 Sumit2342 commented Aug 24, 2026

Copy link
Copy Markdown

What changes were proposed in this pull request?

This PR addresses issue [#851 ] by defining the VectorStore SPI and VectorStoreMetadata contract for the geaflow-ai module.

Major changes include:

• Created the generic VectorStore interface to define standard vector operations (add, delete, search, init).
• Added VectorStoreMetadata with required fields (model_name, dimension, distance, index_version, created_at, format_version) and local fixture
persistence using Gson.
• Implemented strict metadata validation that throws IllegalArgumentException on dimension mismatch, missing metadata, or model
mismatch.

How was this PR tested?

[✓] Tests have Added for the changes
[ ] Production environment verified

Added the VectorStoreMetadataTest which systematically verifies:

• Saving and loading the metadata to/from the JSON local fixture.
• Exception throwing when required fields are missing during validation.
• Exception throwing when testing against dimension or model mismatches.

yaozhongq requested a lite review from Copilot September 9, 2026 06:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Implements the vector store SPI for geaflow-ai, adding a metadata contract plus two concrete store implementations (in-memory and local JSONL persistence), along with basic unit tests.

Changes:

  • Added VectorStore API plus core model types (VectorRecord, VectorQuery, VectorHit) and VectorStoreException.
  • Implemented InMemoryVectorStore and LocalVectorStore (JSONL append + checksum/quarantine).
  • Added DistanceMetric/DistanceUtils and JUnit tests covering basic upsert/search/delete and some validation.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 16 comments.

Show a summary per file
File Description
geaflow-ai/src/test/java/org/apache/geaflow/ai/index/vectorstore/VectorStoreTest.java Adds unit tests exercising both store implementations and some validation scenarios
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/VectorStoreMetadata.java Introduces persisted metadata model with constructor validation and equality
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/VectorStoreException.java Adds domain exception with error codes for consistent failure handling
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/VectorStore.java Defines the SPI for vector operations (upsert/search/delete/close)
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/VectorRecord.java Defines the stored vector payload and associated metadata
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/VectorQuery.java Defines query vector + topK + filter metadata
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/VectorHit.java Defines search result item (id/score/record)
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/LocalVectorStore.java Implements a JSONL-backed store with checksum/quarantine and in-memory index
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/InMemoryVectorStore.java Implements an in-memory store with filtering + topK scoring
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/DistanceUtils.java Implements scoring for cosine/L2/dot-product
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/DistanceMetric.java Adds supported distance metrics enum

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +70 to +78
for (Map.Entry<String, String> entry : query.getFilterMetadata().entrySet()) {
if (entry.getKey().equals("model_name")) {
continue;
}
if (!Objects.equals(record.getMetadata().get(entry.getKey()), entry.getValue()) && !Objects.equals(record.getSourceType(), entry.getValue())) {
match = false;
break;
}
}
* See the License for the specific language governing permissions and
* limitations under the License.
*/

private final Gson gson = new Gson();
private final ConcurrentHashMap<String, VectorRecord> store = new ConcurrentHashMap<>();
private final Set<String> deletedIds = ConcurrentHashMap.newKeySet();
private BufferedWriter writer;
Comment on lines +189 to +197
for (Map.Entry<String, String> entry : query.getFilterMetadata().entrySet()) {
if (entry.getKey().equals("model_name")) {
continue;
}
if (!Objects.equals(record.getMetadata().get(entry.getKey()), entry.getValue()) && !Objects.equals(record.getSourceType(), entry.getValue())) {
match = false;
break;
}
}
Comment on lines +83 to +91
String expectedChecksum = json.get("__checksum").getAsString();

JsonObject dataForChecksum = new JsonParser().parse(line).getAsJsonObject();
dataForChecksum.remove("__checksum");
String actualChecksum = computeChecksum(dataForChecksum.toString());

if (!expectedChecksum.equals(actualChecksum)) {
quarantineLine(line);
return;
testVectorStore(store);
}

private void testVectorStore(VectorStore store) {
assertEquals(1, hits.size());
assertEquals("v1", hits.get(0).getVectorId());

// Dimension mismatch
store.upsert(badRecord);
});

// Model mismatch
store.search(badQuery);
});

// Delete
Comment on lines +24 to +30
/**
* Insert or update a single vector record.
* Upsert is idempotent: same vectorId overwrites the previous record.
*
* @throws VectorStoreException if record.embedding.length != metadata.dimension (DIMENSION_MISMATCH)
* @throws VectorStoreException if required metadata fields are missing (METADATA_INCOMPLETE)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort, defaults to Lite
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /