You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@geaflow.apache.org by "Copilot (via GitHub)" <gi...@apache.org> on 2026/09/09 06:39:28 UTC

Re: [PR] [ISSUE-851] implemented VectorStore and VectorStoreMetadata interfaces with validation and persistence [geaflow]

Copilot commented on code in PR #855:
URL: https://github.com/apache/geaflow/pull/855#discussion_r3965367293


##########
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/InMemoryVectorStore.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geaflow.ai.index.vectorstore;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.PriorityQueue;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class InMemoryVectorStore implements VectorStore {
+    private final VectorStoreMetadata metadata;
+    private final ConcurrentHashMap<String, VectorRecord> store = new ConcurrentHashMap<>();
+    private final Set<String> deletedIds = ConcurrentHashMap.newKeySet();
+
+    public InMemoryVectorStore(VectorStoreMetadata metadata) {
+        this.metadata = Objects.requireNonNull(metadata);
+    }
+
+    @Override
+    public void upsert(VectorRecord record) {
+        if (record.getEmbedding().length != metadata.getDimension()) {
+            throw new VectorStoreException(VectorStoreException.ErrorCode.DIMENSION_MISMATCH,
+                    "Expected dimension " + metadata.getDimension() + ", got " + record.getEmbedding().length);
+        }
+        store.put(record.getVectorId(), record);
+        deletedIds.remove(record.getVectorId());
+    }
+
+    @Override
+    public void upsertBatch(List<VectorRecord> records) {
+        for (VectorRecord record : records) {
+            upsert(record);
+        }
+    }
+
+    @Override
+    public List<VectorHit> search(VectorQuery query) {
+        if (query.getFilterMetadata().containsKey("model_name")) {
+            String filterModel = query.getFilterMetadata().get("model_name");
+            if (!Objects.equals(filterModel, metadata.getModelName())) {
+                throw new VectorStoreException(VectorStoreException.ErrorCode.MODEL_MISMATCH,
+                        "Expected model " + metadata.getModelName() + ", got " + filterModel);
+            }
+        }
+
+        PriorityQueue<VectorHit> hits = new PriorityQueue<>(query.getTopK(), Comparator.comparingDouble(VectorHit::getScore));
+        for (VectorRecord record : store.values()) {
+            if (!deletedIds.contains(record.getVectorId())) {
+                boolean match = true;
+                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;
+                    }
+                }

Review Comment:
   Same filter bug as `LocalVectorStore`: `record.getSourceType()` is compared to the filter value regardless of the filter key, allowing unrelated filters to accidentally match. Restrict `sourceType` comparison to a dedicated key (and otherwise only compare the record's metadata value for `entry.getKey()`).



##########
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/LocalVectorStore.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geaflow.ai.index.vectorstore;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.PriorityQueue;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.zip.CRC32;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LocalVectorStore implements VectorStore {
+    private static final Logger LOGGER = LoggerFactory.getLogger(LocalVectorStore.class);
+
+    private final VectorStoreMetadata metadata;
+    private final Path jsonlPath;
+    private final Path quarantinePath;
+    private final Gson gson = new Gson();
+    private final ConcurrentHashMap<String, VectorRecord> store = new ConcurrentHashMap<>();
+    private final Set<String> deletedIds = ConcurrentHashMap.newKeySet();
+    private BufferedWriter writer;
+
+    public LocalVectorStore(VectorStoreMetadata metadata, Path jsonlPath) {
+        this.metadata = Objects.requireNonNull(metadata);
+        this.jsonlPath = Objects.requireNonNull(jsonlPath);
+        this.quarantinePath = jsonlPath.resolveSibling(jsonlPath.getFileName() + ".quarantine");
+        init();
+    }
+
+    private void init() {
+        if (Files.exists(jsonlPath)) {
+            try (BufferedReader reader = Files.newBufferedReader(jsonlPath, StandardCharsets.UTF_8)) {
+                String line;
+                while ((line = reader.readLine()) != null) {
+                    processLine(line);
+                }
+            } catch (IOException e) {
+                throw new VectorStoreException(VectorStoreException.ErrorCode.PERSISTENCE_ERROR, "Failed to read store file", e);
+            }
+        }
+        try {
+            this.writer = Files.newBufferedWriter(jsonlPath, StandardCharsets.UTF_8, 
+                    StandardOpenOption.CREATE, StandardOpenOption.APPEND);
+        } catch (IOException e) {
+            throw new VectorStoreException(VectorStoreException.ErrorCode.PERSISTENCE_ERROR, "Failed to open store file for writing", e);
+        }
+    }
+
+    private void processLine(String line) {
+        try {
+            JsonObject json = new JsonParser().parse(line).getAsJsonObject();
+            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;

Review Comment:
   Lines without a `__checksum` field (e.g., from earlier formats or manually created fixtures) will throw at `json.get(\"__checksum\")...` and be quarantined silently, which can drop valid data during upgrades. If backward compatibility is required, handle missing checksum explicitly (e.g., accept legacy lines when `__checksum` is absent, or fail-fast with a clear `FORMAT_VERSION_UNKNOWN`/`PERSISTENCE_ERROR`). Also, parsing the same line twice is unnecessary—parse once and clone/remove fields from the parsed object.



##########
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/LocalVectorStore.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+

Review Comment:
   `LocalVectorStore` uses concurrent collections but the `BufferedWriter` and file appends are not thread-safe. Concurrent calls to `upsert` / `upsertBatch` / `markDeleted` can interleave writes and corrupt the JSONL file, and `writer.flush()`/`writer.close()` can race. Consider guarding all write/flush/close paths with a single lock (or making the entire store explicitly single-threaded and enforcing it), and ensure `close()` cannot run concurrently with writes.



##########
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/LocalVectorStore.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geaflow.ai.index.vectorstore;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.PriorityQueue;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.zip.CRC32;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LocalVectorStore implements VectorStore {
+    private static final Logger LOGGER = LoggerFactory.getLogger(LocalVectorStore.class);
+
+    private final VectorStoreMetadata metadata;
+    private final Path jsonlPath;
+    private final Path quarantinePath;
+    private final Gson gson = new Gson();
+    private final ConcurrentHashMap<String, VectorRecord> store = new ConcurrentHashMap<>();
+    private final Set<String> deletedIds = ConcurrentHashMap.newKeySet();
+    private BufferedWriter writer;

Review Comment:
   `LocalVectorStore` uses concurrent collections but the `BufferedWriter` and file appends are not thread-safe. Concurrent calls to `upsert` / `upsertBatch` / `markDeleted` can interleave writes and corrupt the JSONL file, and `writer.flush()`/`writer.close()` can race. Consider guarding all write/flush/close paths with a single lock (or making the entire store explicitly single-threaded and enforcing it), and ensure `close()` cannot run concurrently with writes.



##########
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/LocalVectorStore.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geaflow.ai.index.vectorstore;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.PriorityQueue;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.zip.CRC32;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LocalVectorStore implements VectorStore {
+    private static final Logger LOGGER = LoggerFactory.getLogger(LocalVectorStore.class);
+
+    private final VectorStoreMetadata metadata;
+    private final Path jsonlPath;
+    private final Path quarantinePath;
+    private final Gson gson = new Gson();
+    private final ConcurrentHashMap<String, VectorRecord> store = new ConcurrentHashMap<>();
+    private final Set<String> deletedIds = ConcurrentHashMap.newKeySet();
+    private BufferedWriter writer;
+
+    public LocalVectorStore(VectorStoreMetadata metadata, Path jsonlPath) {
+        this.metadata = Objects.requireNonNull(metadata);
+        this.jsonlPath = Objects.requireNonNull(jsonlPath);
+        this.quarantinePath = jsonlPath.resolveSibling(jsonlPath.getFileName() + ".quarantine");
+        init();
+    }
+
+    private void init() {
+        if (Files.exists(jsonlPath)) {
+            try (BufferedReader reader = Files.newBufferedReader(jsonlPath, StandardCharsets.UTF_8)) {
+                String line;
+                while ((line = reader.readLine()) != null) {
+                    processLine(line);
+                }
+            } catch (IOException e) {
+                throw new VectorStoreException(VectorStoreException.ErrorCode.PERSISTENCE_ERROR, "Failed to read store file", e);
+            }
+        }
+        try {
+            this.writer = Files.newBufferedWriter(jsonlPath, StandardCharsets.UTF_8, 
+                    StandardOpenOption.CREATE, StandardOpenOption.APPEND);
+        } catch (IOException e) {
+            throw new VectorStoreException(VectorStoreException.ErrorCode.PERSISTENCE_ERROR, "Failed to open store file for writing", e);
+        }
+    }
+
+    private void processLine(String line) {
+        try {
+            JsonObject json = new JsonParser().parse(line).getAsJsonObject();
+            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;
+            }
+
+            String vectorId = json.get("vectorId").getAsString();
+            if (json.has("__deleted") && json.get("__deleted").getAsBoolean()) {
+                store.remove(vectorId);
+                deletedIds.add(vectorId);
+            } else {
+                VectorRecord record = gson.fromJson(dataForChecksum, VectorRecord.class);
+                store.put(vectorId, record);
+                deletedIds.remove(vectorId);
+            }
+        } catch (Exception e) {
+            quarantineLine(line);
+        }
+    }
+
+    private void quarantineLine(String line) {
+        try {
+            Files.write(quarantinePath, (line + System.lineSeparator()).getBytes(StandardCharsets.UTF_8), 
+                    StandardOpenOption.CREATE, StandardOpenOption.APPEND);
+        } catch (IOException e) {
+            LOGGER.warn("Ignoring quarantine IOException");
+        }
+    }
+

Review Comment:
   The quarantine failure log drops useful debugging context (no exception, no path). Log the exception and the quarantine file path (and ideally record count/line prefix), otherwise quarantine write failures are very hard to diagnose.



##########
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/LocalVectorStore.java:
##########
@@ -0,0 +1,256 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geaflow.ai.index.vectorstore;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.PriorityQueue;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.zip.CRC32;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class LocalVectorStore implements VectorStore {
+    private static final Logger LOGGER = LoggerFactory.getLogger(LocalVectorStore.class);
+
+    private final VectorStoreMetadata metadata;
+    private final Path jsonlPath;
+    private final Path quarantinePath;
+    private final Gson gson = new Gson();
+    private final ConcurrentHashMap<String, VectorRecord> store = new ConcurrentHashMap<>();
+    private final Set<String> deletedIds = ConcurrentHashMap.newKeySet();
+    private BufferedWriter writer;
+
+    public LocalVectorStore(VectorStoreMetadata metadata, Path jsonlPath) {
+        this.metadata = Objects.requireNonNull(metadata);
+        this.jsonlPath = Objects.requireNonNull(jsonlPath);
+        this.quarantinePath = jsonlPath.resolveSibling(jsonlPath.getFileName() + ".quarantine");
+        init();
+    }
+
+    private void init() {
+        if (Files.exists(jsonlPath)) {
+            try (BufferedReader reader = Files.newBufferedReader(jsonlPath, StandardCharsets.UTF_8)) {
+                String line;
+                while ((line = reader.readLine()) != null) {
+                    processLine(line);
+                }
+            } catch (IOException e) {
+                throw new VectorStoreException(VectorStoreException.ErrorCode.PERSISTENCE_ERROR, "Failed to read store file", e);
+            }
+        }
+        try {
+            this.writer = Files.newBufferedWriter(jsonlPath, StandardCharsets.UTF_8, 
+                    StandardOpenOption.CREATE, StandardOpenOption.APPEND);
+        } catch (IOException e) {
+            throw new VectorStoreException(VectorStoreException.ErrorCode.PERSISTENCE_ERROR, "Failed to open store file for writing", e);
+        }
+    }
+
+    private void processLine(String line) {
+        try {
+            JsonObject json = new JsonParser().parse(line).getAsJsonObject();
+            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;
+            }
+
+            String vectorId = json.get("vectorId").getAsString();
+            if (json.has("__deleted") && json.get("__deleted").getAsBoolean()) {
+                store.remove(vectorId);
+                deletedIds.add(vectorId);
+            } else {
+                VectorRecord record = gson.fromJson(dataForChecksum, VectorRecord.class);
+                store.put(vectorId, record);
+                deletedIds.remove(vectorId);
+            }
+        } catch (Exception e) {
+            quarantineLine(line);
+        }
+    }
+
+    private void quarantineLine(String line) {
+        try {
+            Files.write(quarantinePath, (line + System.lineSeparator()).getBytes(StandardCharsets.UTF_8), 
+                    StandardOpenOption.CREATE, StandardOpenOption.APPEND);
+        } catch (IOException e) {
+            LOGGER.warn("Ignoring quarantine IOException");
+        }
+    }
+
+    private String computeChecksum(String data) {
+        CRC32 crc32 = new CRC32();
+        crc32.update(data.getBytes(StandardCharsets.UTF_8));
+        return Long.toHexString(crc32.getValue());
+    }
+
+    private void appendLine(JsonObject json) {
+        String dataStr = json.toString();
+        String checksum = computeChecksum(dataStr);
+        json.addProperty("__checksum", checksum);
+        try {
+            writer.write(json.toString());
+            writer.newLine();
+        } catch (IOException e) {
+            throw new VectorStoreException(VectorStoreException.ErrorCode.PERSISTENCE_ERROR, "Failed to write record", e);
+        }
+    }
+
+    @Override
+    public void upsert(VectorRecord record) {
+        if (record.getEmbedding().length != metadata.getDimension()) {
+            throw new VectorStoreException(VectorStoreException.ErrorCode.DIMENSION_MISMATCH,
+                    "Expected dimension " + metadata.getDimension() + ", got " + record.getEmbedding().length);
+        }
+        JsonObject json = gson.toJsonTree(record).getAsJsonObject();
+        appendLine(json);
+        
+        store.put(record.getVectorId(), record);
+        deletedIds.remove(record.getVectorId());
+
+        try {
+            writer.flush();
+        } catch (IOException e) {
+            throw new VectorStoreException(VectorStoreException.ErrorCode.PERSISTENCE_ERROR, "Failed to flush record", e);
+        }
+    }
+
+    @Override
+    public void upsertBatch(List<VectorRecord> records) {
+        for (VectorRecord record : records) {
+            if (record.getEmbedding().length != metadata.getDimension()) {
+                throw new VectorStoreException(VectorStoreException.ErrorCode.DIMENSION_MISMATCH,
+                        "Expected dimension " + metadata.getDimension() + ", got " + record.getEmbedding().length);
+            }
+            JsonObject json = gson.toJsonTree(record).getAsJsonObject();
+            appendLine(json);
+            
+            store.put(record.getVectorId(), record);
+            deletedIds.remove(record.getVectorId());
+        }
+        try {
+            writer.flush();
+        } catch (IOException e) {
+            throw new VectorStoreException(VectorStoreException.ErrorCode.PERSISTENCE_ERROR, "Failed to flush batch", e);
+        }
+    }
+
+    @Override
+    public List<VectorHit> search(VectorQuery query) {
+        if (query.getFilterMetadata().containsKey("model_name")) {
+            String filterModel = query.getFilterMetadata().get("model_name");
+            if (!Objects.equals(filterModel, metadata.getModelName())) {
+                throw new VectorStoreException(VectorStoreException.ErrorCode.MODEL_MISMATCH,
+                        "Expected model " + metadata.getModelName() + ", got " + filterModel);
+            }
+        }
+
+        PriorityQueue<VectorHit> hits = new PriorityQueue<>(query.getTopK(), Comparator.comparingDouble(VectorHit::getScore));
+
+        for (VectorRecord record : store.values()) {
+            if (!deletedIds.contains(record.getVectorId())) {
+                boolean match = true;
+                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;
+                    }
+                }

Review Comment:
   The filter predicate is logically incorrect: it compares `record.getSourceType()` to `entry.getValue()` for every filter key, which can cause false positives (e.g., an unrelated filter like `foo=bar` matches any record whose `sourceType` equals `bar`). Fix by only comparing `sourceType` when the filter key explicitly targets it (e.g., `source_type`), otherwise compare against `record.getMetadata().get(entry.getKey())` only. Note: the same issue exists in `InMemoryVectorStore`.



##########
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/VectorRecord.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geaflow.ai.index.vectorstore;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class VectorRecord {
+    private final String vectorId;
+    private final double[] embedding;
+    private final String sourceType;
+    private final String sourceId;
+    private final Map<String, String> metadata;
+
+    public VectorRecord(String vectorId, double[] embedding, String sourceType, String sourceId, Map<String, String> metadata) {
+        if (vectorId == null || vectorId.isEmpty()) {
+            throw new IllegalArgumentException("vectorId cannot be null or empty");
+        }
+        if (embedding == null || embedding.length == 0) {
+            throw new IllegalArgumentException("embedding cannot be null or empty");
+        }
+        if (sourceType == null || sourceType.isEmpty()) {
+            throw new IllegalArgumentException("sourceType cannot be null or empty");
+        }
+        if (sourceId == null || sourceId.isEmpty()) {
+            throw new IllegalArgumentException("sourceId cannot be null or empty");
+        }
+        this.vectorId = vectorId;
+        this.embedding = embedding;
+        this.sourceType = sourceType;
+        this.sourceId = sourceId;
+        this.metadata = metadata == null ? Collections.emptyMap() : metadata;

Review Comment:
   This stores and returns mutable references (`double[] embedding` and `Map metadata`) without defensive copies. Callers can mutate the record after insertion (or mutate the returned references), changing search behavior and potentially corrupting persisted output. Consider copying arrays/maps in the constructor and returning either copies or unmodifiable views from getters.



##########
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/VectorRecord.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geaflow.ai.index.vectorstore;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class VectorRecord {
+    private final String vectorId;
+    private final double[] embedding;
+    private final String sourceType;
+    private final String sourceId;
+    private final Map<String, String> metadata;
+
+    public VectorRecord(String vectorId, double[] embedding, String sourceType, String sourceId, Map<String, String> metadata) {
+        if (vectorId == null || vectorId.isEmpty()) {
+            throw new IllegalArgumentException("vectorId cannot be null or empty");
+        }
+        if (embedding == null || embedding.length == 0) {
+            throw new IllegalArgumentException("embedding cannot be null or empty");
+        }
+        if (sourceType == null || sourceType.isEmpty()) {
+            throw new IllegalArgumentException("sourceType cannot be null or empty");
+        }
+        if (sourceId == null || sourceId.isEmpty()) {
+            throw new IllegalArgumentException("sourceId cannot be null or empty");
+        }
+        this.vectorId = vectorId;
+        this.embedding = embedding;
+        this.sourceType = sourceType;
+        this.sourceId = sourceId;
+        this.metadata = metadata == null ? Collections.emptyMap() : metadata;
+    }
+
+    public String getVectorId() {
+        return vectorId;
+    }
+
+    public double[] getEmbedding() {
+        return embedding;
+    }

Review Comment:
   This stores and returns mutable references (`double[] embedding` and `Map metadata`) without defensive copies. Callers can mutate the record after insertion (or mutate the returned references), changing search behavior and potentially corrupting persisted output. Consider copying arrays/maps in the constructor and returning either copies or unmodifiable views from getters.



##########
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/VectorStore.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geaflow.ai.index.vectorstore;
+
+import java.util.List;
+
+public interface VectorStore {

Review Comment:
   Since `VectorStore` has `close()`, it should extend `AutoCloseable` to support try-with-resources and encourage correct lifecycle management. This also improves safety in tests and callers where exceptions might otherwise skip `close()`.



##########
geaflow-ai/src/test/java/org/apache/geaflow/ai/index/vectorstore/VectorStoreTest.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geaflow.ai.index.vectorstore;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class VectorStoreTest {
+
+    private Path tempFile;
+    private VectorStoreMetadata metadata;
+
+    @BeforeEach
+    public void setUp() throws IOException {
+        tempFile = Files.createTempFile("vector_store_test", ".jsonl");
+        metadata = new VectorStoreMetadata("test_model", 128, DistanceMetric.COSINE, "1.0", System.currentTimeMillis(), 1);
+    }
+
+    @AfterEach
+    public void tearDown() throws IOException {
+        Files.deleteIfExists(tempFile);
+        Files.deleteIfExists(tempFile.resolveSibling(tempFile.getFileName() + ".quarantine"));
+    }
+
+    @Test
+    public void testMetadataValidation() {
+        assertThrows(IllegalArgumentException.class, () -> {
+            new VectorStoreMetadata("", 128, DistanceMetric.COSINE, "1.0", 0, 1);
+        });
+        
+        assertThrows(IllegalArgumentException.class, () -> {
+            new VectorStoreMetadata("test", 0, DistanceMetric.COSINE, "1.0", 0, 1);
+        });
+        
+        assertThrows(IllegalArgumentException.class, () -> {
+            new VectorStoreMetadata("test", 128, null, "1.0", 0, 1);
+        });
+    }
+
+    @Test
+    public void testInMemoryVectorStore() {
+        VectorStore store = new InMemoryVectorStore(metadata);
+        testVectorStore(store);
+    }
+
+    @Test
+    public void testLocalVectorStore() {
+        VectorStore store = new LocalVectorStore(metadata, tempFile);
+        testVectorStore(store);
+    }
+
+    private void testVectorStore(VectorStore store) {

Review Comment:
   The new filtering behavior (non-`model_name` metadata filtering, and the special-casing of `sourceType` in filtering) is not covered by tests here, and neither is the LocalVectorStore checksum/quarantine behavior. Add targeted tests that (1) verify metadata filters match only on the intended keys, and (2) verify checksum mismatch quarantines exactly the bad line (and valid lines still load).



##########
geaflow-ai/src/test/java/org/apache/geaflow/ai/index/vectorstore/VectorStoreTest.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geaflow.ai.index.vectorstore;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class VectorStoreTest {
+
+    private Path tempFile;
+    private VectorStoreMetadata metadata;
+
+    @BeforeEach
+    public void setUp() throws IOException {
+        tempFile = Files.createTempFile("vector_store_test", ".jsonl");
+        metadata = new VectorStoreMetadata("test_model", 128, DistanceMetric.COSINE, "1.0", System.currentTimeMillis(), 1);
+    }
+
+    @AfterEach
+    public void tearDown() throws IOException {
+        Files.deleteIfExists(tempFile);
+        Files.deleteIfExists(tempFile.resolveSibling(tempFile.getFileName() + ".quarantine"));
+    }
+
+    @Test
+    public void testMetadataValidation() {
+        assertThrows(IllegalArgumentException.class, () -> {
+            new VectorStoreMetadata("", 128, DistanceMetric.COSINE, "1.0", 0, 1);
+        });
+        
+        assertThrows(IllegalArgumentException.class, () -> {
+            new VectorStoreMetadata("test", 0, DistanceMetric.COSINE, "1.0", 0, 1);
+        });
+        
+        assertThrows(IllegalArgumentException.class, () -> {
+            new VectorStoreMetadata("test", 128, null, "1.0", 0, 1);
+        });
+    }
+
+    @Test
+    public void testInMemoryVectorStore() {
+        VectorStore store = new InMemoryVectorStore(metadata);
+        testVectorStore(store);
+    }
+
+    @Test
+    public void testLocalVectorStore() {
+        VectorStore store = new LocalVectorStore(metadata, tempFile);
+        testVectorStore(store);
+    }
+
+    private void testVectorStore(VectorStore store) {
+        double[] embedding = new double[128];
+        embedding[0] = 1.0;
+        
+        VectorRecord record = new VectorRecord("v1", embedding, "chunk", "c1", Collections.emptyMap());
+        store.upsert(record);
+        
+        VectorQuery query = new VectorQuery(embedding, 10, Collections.emptyMap());
+        List<VectorHit> hits = store.search(query);
+        
+        assertEquals(1, hits.size());
+        assertEquals("v1", hits.get(0).getVectorId());
+        
+        // Dimension mismatch

Review Comment:
   The new filtering behavior (non-`model_name` metadata filtering, and the special-casing of `sourceType` in filtering) is not covered by tests here, and neither is the LocalVectorStore checksum/quarantine behavior. Add targeted tests that (1) verify metadata filters match only on the intended keys, and (2) verify checksum mismatch quarantines exactly the bad line (and valid lines still load).



##########
geaflow-ai/src/test/java/org/apache/geaflow/ai/index/vectorstore/VectorStoreTest.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geaflow.ai.index.vectorstore;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class VectorStoreTest {
+
+    private Path tempFile;
+    private VectorStoreMetadata metadata;
+
+    @BeforeEach
+    public void setUp() throws IOException {
+        tempFile = Files.createTempFile("vector_store_test", ".jsonl");
+        metadata = new VectorStoreMetadata("test_model", 128, DistanceMetric.COSINE, "1.0", System.currentTimeMillis(), 1);
+    }
+
+    @AfterEach
+    public void tearDown() throws IOException {
+        Files.deleteIfExists(tempFile);
+        Files.deleteIfExists(tempFile.resolveSibling(tempFile.getFileName() + ".quarantine"));
+    }
+
+    @Test
+    public void testMetadataValidation() {
+        assertThrows(IllegalArgumentException.class, () -> {
+            new VectorStoreMetadata("", 128, DistanceMetric.COSINE, "1.0", 0, 1);
+        });
+        
+        assertThrows(IllegalArgumentException.class, () -> {
+            new VectorStoreMetadata("test", 0, DistanceMetric.COSINE, "1.0", 0, 1);
+        });
+        
+        assertThrows(IllegalArgumentException.class, () -> {
+            new VectorStoreMetadata("test", 128, null, "1.0", 0, 1);
+        });
+    }
+
+    @Test
+    public void testInMemoryVectorStore() {
+        VectorStore store = new InMemoryVectorStore(metadata);
+        testVectorStore(store);
+    }
+
+    @Test
+    public void testLocalVectorStore() {
+        VectorStore store = new LocalVectorStore(metadata, tempFile);
+        testVectorStore(store);
+    }
+
+    private void testVectorStore(VectorStore store) {
+        double[] embedding = new double[128];
+        embedding[0] = 1.0;
+        
+        VectorRecord record = new VectorRecord("v1", embedding, "chunk", "c1", Collections.emptyMap());
+        store.upsert(record);
+        
+        VectorQuery query = new VectorQuery(embedding, 10, Collections.emptyMap());
+        List<VectorHit> hits = store.search(query);
+        
+        assertEquals(1, hits.size());
+        assertEquals("v1", hits.get(0).getVectorId());
+        
+        // Dimension mismatch
+        double[] badEmbedding = new double[64];
+        VectorRecord badRecord = new VectorRecord("v2", badEmbedding, "chunk", "c2", Collections.emptyMap());
+        
+        assertThrows(VectorStoreException.class, () -> {
+            store.upsert(badRecord);
+        });
+        
+        // Model mismatch

Review Comment:
   The new filtering behavior (non-`model_name` metadata filtering, and the special-casing of `sourceType` in filtering) is not covered by tests here, and neither is the LocalVectorStore checksum/quarantine behavior. Add targeted tests that (1) verify metadata filters match only on the intended keys, and (2) verify checksum mismatch quarantines exactly the bad line (and valid lines still load).



##########
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/VectorStore.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geaflow.ai.index.vectorstore;
+
+import java.util.List;
+
+public interface VectorStore {
+
+    /**
+     * 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)
+     */
+    void upsert(VectorRecord record);
+
+    /**
+     * Batch insert/update. Atomic per record; partial failure does not
+     * roll back already-committed records.
+     */
+    void upsertBatch(List<VectorRecord> records);
+
+    /**
+     * Search for nearest vectors using the configured distance metric.
+     * Results are ordered by score descending (best match first).
+     *
+     * @return empty list if no results match, never null
+     * @throws VectorStoreException if filterMetadata specifies
+     *         a model_name different from the store's model_name (MODEL_MISMATCH)
+     */
+    List<VectorHit> search(VectorQuery query);
+
+    /**
+     * Soft-delete a vector by id. The record remains on disk but is
+     * excluded from future search results.
+     *
+     * @throws VectorStoreException if vectorId does not exist (RECORD_NOT_FOUND)
+     */
+    void markDeleted(String vectorId);
+
+    /**
+     * Returns metadata about this store instance.
+     */
+    VectorStoreMetadata getMetadata();
+
+    /**
+     * Release resources. Implementations must flush pending writes before returning.
+     */
+    void close();
+}

Review Comment:
   Since `VectorStore` has `close()`, it should extend `AutoCloseable` to support try-with-resources and encourage correct lifecycle management. This also improves safety in tests and callers where exceptions might otherwise skip `close()`.



##########
geaflow-ai/src/test/java/org/apache/geaflow/ai/index/vectorstore/VectorStoreTest.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geaflow.ai.index.vectorstore;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class VectorStoreTest {
+
+    private Path tempFile;
+    private VectorStoreMetadata metadata;
+
+    @BeforeEach
+    public void setUp() throws IOException {
+        tempFile = Files.createTempFile("vector_store_test", ".jsonl");
+        metadata = new VectorStoreMetadata("test_model", 128, DistanceMetric.COSINE, "1.0", System.currentTimeMillis(), 1);
+    }
+
+    @AfterEach
+    public void tearDown() throws IOException {
+        Files.deleteIfExists(tempFile);
+        Files.deleteIfExists(tempFile.resolveSibling(tempFile.getFileName() + ".quarantine"));
+    }
+
+    @Test
+    public void testMetadataValidation() {
+        assertThrows(IllegalArgumentException.class, () -> {
+            new VectorStoreMetadata("", 128, DistanceMetric.COSINE, "1.0", 0, 1);
+        });
+        
+        assertThrows(IllegalArgumentException.class, () -> {
+            new VectorStoreMetadata("test", 0, DistanceMetric.COSINE, "1.0", 0, 1);
+        });
+        
+        assertThrows(IllegalArgumentException.class, () -> {
+            new VectorStoreMetadata("test", 128, null, "1.0", 0, 1);
+        });
+    }
+
+    @Test
+    public void testInMemoryVectorStore() {
+        VectorStore store = new InMemoryVectorStore(metadata);
+        testVectorStore(store);
+    }
+
+    @Test
+    public void testLocalVectorStore() {
+        VectorStore store = new LocalVectorStore(metadata, tempFile);
+        testVectorStore(store);
+    }
+
+    private void testVectorStore(VectorStore store) {
+        double[] embedding = new double[128];
+        embedding[0] = 1.0;
+        
+        VectorRecord record = new VectorRecord("v1", embedding, "chunk", "c1", Collections.emptyMap());
+        store.upsert(record);
+        
+        VectorQuery query = new VectorQuery(embedding, 10, Collections.emptyMap());
+        List<VectorHit> hits = store.search(query);
+        
+        assertEquals(1, hits.size());
+        assertEquals("v1", hits.get(0).getVectorId());
+        
+        // Dimension mismatch
+        double[] badEmbedding = new double[64];
+        VectorRecord badRecord = new VectorRecord("v2", badEmbedding, "chunk", "c2", Collections.emptyMap());
+        
+        assertThrows(VectorStoreException.class, () -> {
+            store.upsert(badRecord);
+        });
+        
+        // Model mismatch
+        VectorQuery badQuery = new VectorQuery(embedding, 10, Collections.singletonMap("model_name", "wrong_model"));
+        assertThrows(VectorStoreException.class, () -> {
+            store.search(badQuery);
+        });
+        
+        // Delete

Review Comment:
   The new filtering behavior (non-`model_name` metadata filtering, and the special-casing of `sourceType` in filtering) is not covered by tests here, and neither is the LocalVectorStore checksum/quarantine behavior. Add targeted tests that (1) verify metadata filters match only on the intended keys, and (2) verify checksum mismatch quarantines exactly the bad line (and valid lines still load).



##########
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/VectorStore.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geaflow.ai.index.vectorstore;
+
+import java.util.List;
+
+public interface VectorStore {
+
+    /**
+     * 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)
+     */

Review Comment:
   The PR description mentions an `init` operation as part of the VectorStore SPI, but the interface does not define `init()` (and implementations initialize via constructors). Either update the PR description to match the actual API, or add a formal initialization method if callers are expected to explicitly initialize.



##########
geaflow-ai/src/main/java/org/apache/geaflow/ai/index/vectorstore/VectorRecord.java:
##########
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geaflow.ai.index.vectorstore;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class VectorRecord {
+    private final String vectorId;
+    private final double[] embedding;
+    private final String sourceType;
+    private final String sourceId;
+    private final Map<String, String> metadata;
+
+    public VectorRecord(String vectorId, double[] embedding, String sourceType, String sourceId, Map<String, String> metadata) {
+        if (vectorId == null || vectorId.isEmpty()) {
+            throw new IllegalArgumentException("vectorId cannot be null or empty");
+        }
+        if (embedding == null || embedding.length == 0) {
+            throw new IllegalArgumentException("embedding cannot be null or empty");
+        }
+        if (sourceType == null || sourceType.isEmpty()) {
+            throw new IllegalArgumentException("sourceType cannot be null or empty");
+        }
+        if (sourceId == null || sourceId.isEmpty()) {
+            throw new IllegalArgumentException("sourceId cannot be null or empty");
+        }
+        this.vectorId = vectorId;
+        this.embedding = embedding;
+        this.sourceType = sourceType;
+        this.sourceId = sourceId;
+        this.metadata = metadata == null ? Collections.emptyMap() : metadata;
+    }
+
+    public String getVectorId() {
+        return vectorId;
+    }
+
+    public double[] getEmbedding() {
+        return embedding;
+    }
+
+    public String getSourceType() {
+        return sourceType;
+    }
+
+    public String getSourceId() {
+        return sourceId;
+    }
+
+    public Map<String, String> getMetadata() {
+        return metadata;
+    }

Review Comment:
   This stores and returns mutable references (`double[] embedding` and `Map metadata`) without defensive copies. Callers can mutate the record after insertion (or mutate the returned references), changing search behavior and potentially corrupting persisted output. Consider copying arrays/maps in the constructor and returning either copies or unmodifiable views from getters.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@geaflow.apache.org
For additional commands, e-mail: issues-help@geaflow.apache.org