Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ jobs:
if: github.ref == 'refs/heads/main' || github.base_ref == 'main'
run: python3 tools/check-skill-schema.py

install_sh_tests:
name: install.sh tests (${{ matrix.os }})
tools_script_tests:
name: tools script tests (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -65,7 +65,7 @@ jobs:
- name: Install bash 4+ (macOS)
if: runner.os == 'macOS'
run: brew install bash
- name: Run install.sh tests
- name: Run tools script tests
run: bash tools/test/run.sh

build_backend_tests:
Expand Down Expand Up @@ -245,6 +245,33 @@ jobs:
LOG_LEVEL: INFO
run: tools/ut.sh -j -e -f ${{ matrix.flink-version }}

elasticsearch_tests:
name: Elasticsearch vector-store tests
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- uses: actions/checkout@v4
- name: Install Java
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Install flink-agents Java
run: bash tools/build.sh -j
- name: Start Elasticsearch
run: |
docker compose -f tools/docker/elasticsearch/docker-compose.yml down -v
docker compose -f tools/docker/elasticsearch/docker-compose.yml up -d
timeout 180 bash -c 'until curl -fsS http://localhost:9200/_cluster/health; do sleep 5; done'
- name: Run Elasticsearch tests
env:
ES_HOST: http://localhost:9200
run: |
mvn -B --no-transfer-progress -pl integrations/vector-stores/elasticsearch -am -Dspotless.skip=true -Drat.skip=true -Dtest=ElasticsearchVectorStoreTest -Dsurefire.failIfNoSpecifiedTests=false test
- name: Stop Elasticsearch
if: always()
run: docker compose -f tools/docker/elasticsearch/docker-compose.yml down -v

cross_language_tests:
name: cross-language [${{ matrix.os }}] [python-${{ matrix.python-version}}] [java-${{ matrix.java-version}}]
runs-on: ${{ matrix.os }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
import org.apache.flink.agents.api.vectorstores.CollectionManageableVectorStore;
import org.apache.flink.agents.api.vectorstores.Document;
import org.apache.flink.agents.api.vectorstores.VectorStoreQuery;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.mockito.Mockito;

import java.util.ArrayList;
Expand All @@ -48,7 +49,7 @@
* <p>For {@link ElasticsearchVectorStore} doesn't support security check yet, when start the
* container, should add "-e xpack.security.enabled=false" option.
*/
@Disabled("Should setup Elasticsearch server.")
@EnabledIfEnvironmentVariable(named = "ES_HOST", matches = ".+")
public class ElasticsearchVectorStoreTest {
public static BaseVectorStore store;

Expand All @@ -64,18 +65,27 @@ public static Resource getResource(String name, ResourceType type) {
}

@BeforeAll
public static void initialize() {
public static void initialize() throws Exception {
String esHost = System.getenv().getOrDefault("ES_HOST", "http://localhost:9200");
final ResourceDescriptor.Builder builder =
ResourceDescriptor.Builder.newBuilder(ElasticsearchVectorStore.class.getName())
.addInitialArgument("embedding_model", "embeddingModel")
.addInitialArgument("host", "localhost:9200")
.addInitialArgument("host", esHost)
.addInitialArgument("dims", 5)
.addInitialArgument("username", "elastic")
.addInitialArgument("password", System.getenv("ES_PASSWORD"));
store =
new ElasticsearchVectorStore(
builder.build(),
ResourceContext.fromGetResource(ElasticsearchVectorStoreTest::getResource));
store.open();
}

@AfterAll
public static void cleanup() throws Exception {
if (store != null) {
store.close();
}
}

@Test
Expand Down Expand Up @@ -121,6 +131,7 @@ public void testDocumentManagement() throws Exception {

// test get all documents
List<Document> all = store.get(null, name, null, null, Collections.emptyMap());
all.forEach(document -> document.setScore(null));
Assertions.assertEquals(documents, all);

// test get specific document
Expand All @@ -138,6 +149,7 @@ public void testDocumentManagement() throws Exception {
store.delete(Collections.singletonList("doc1"), name, null, Collections.emptyMap());
Thread.sleep(1000);
List<Document> remain = store.get(null, name, null, null, Collections.emptyMap());
remain.forEach(document -> document.setScore(null));
Assertions.assertEquals(1, remain.size());
Assertions.assertEquals(documents.get(1), remain.get(0));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,48 @@ def check_result(*, result_dir: Path) -> None:
for record in actual_result:
records[f"{record.name}.{record.count}"] = record

assert "alice.2" in records, f"missing alice.2; got {sorted(records)}"
assert "bob.2" in records, f"missing bob.2; got {sorted(records)}"
# The extraction model decides whether each key's two facts collapse into a
# single item or stay separate, so the item count is not fixed. Each set is
# reported alongside the other's failure to tell a per-key miss from a
# store-wide one.
items = records["alice.2"].items
# LLMs may treat different review comments as updates to the same
# fact or as distinct facts.
assert len(items) == 1
item: MemorySetItem = items[-1]
assert item.created_at < item.updated_at
assert "bananas" in item.value
values = [item.value for item in items or []]
bob_values = [item.value for item in records["bob.2"].items or []]
# A scoping break misattributes in either direction. alice's facts landing
# in bob's set leaves alice's set short rather than inflated, so check that
# direction ahead of the emptiness assertion below, which would otherwise
# report the symptom in place of the cause. bob's set has to be populated
# for that scan to carry any weight, since an empty one satisfies it
# without ever being examined.
assert bob_values, f"bob's memory set is empty (alice's set: {values})"
bob_leaked = [
value
for value in bob_values
if "watermelon" in value.lower() or "bananas" in value.lower()
]
assert not bob_leaked, f"bob's set contains alice's facts: {bob_values}"
assert values, f"alice's memory set is empty (bob's set: {bob_values})"

# The stored text is the model's paraphrase of the input, so match loosely.
assert any("bananas" in value.lower() for value in values), (
f"no stored item carries the updated fact: {values}"
)
# Each partition key is scoped to its own memories, so bob's facts must
# never surface in alice's set.
leaked = [
value
for value in values
if "swimming" in value.lower() or "vegetarian" in value.lower()
]
assert not leaked, f"alice's set contains bob's facts: {values}"
# Both timestamps are populated whether an item was created or updated, and
# the parser turns an unrecognized format into None rather than raising.
assert all(item.created_at and item.updated_at for item in items), (
f"stored items are missing timestamps: "
f"{[(item.created_at, item.updated_at) for item in items]}"
)

# verify async add doesn't block process other key
assert datetime.fromisoformat(
Expand Down
17 changes: 17 additions & 0 deletions tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@

set -e

show_help() {
cat <<EOF
Build Flink Agents Java and Python artifacts

Usage: $0 [options]

Options:
-j, --java Build only Java artifacts
-p, --python Build only Python artifacts
-h, --help Display this help message
EOF
}

# Parse command-line arguments
build_java=true
build_python=true
Expand All @@ -28,6 +41,10 @@ while [[ "$#" -gt 0 ]]; do
-j|--java)
build_python=false
;;
-h|--help)
show_help
exit 0
;;
*)
echo "Error: Unknown option '$1'" >&2
show_help
Expand Down
47 changes: 47 additions & 0 deletions tools/test/integration/build_help.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bats

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

BUILD_SCRIPT="${BATS_TEST_DIRNAME}/../../build.sh"

@test "build --help prints usage and exits 0" {
run bash "$BUILD_SCRIPT" --help

[ "$status" -eq 0 ]
[[ "$output" == *"Build Flink Agents Java and Python artifacts"* ]]
[[ "$output" == *"Usage:"* ]]
[[ "$output" == *"--java"* ]]
[[ "$output" == *"--python"* ]]
}

@test "build -h prints usage and exits 0" {
run bash "$BUILD_SCRIPT" -h

[ "$status" -eq 0 ]
[[ "$output" == *"Usage:"* ]]
}

@test "build rejects an unknown option with usage" {
run bash "$BUILD_SCRIPT" --no-such-option

[ "$status" -eq 1 ]
[[ "$output" == *"Error: Unknown option '--no-such-option'"* ]]
[[ "$output" == *"Usage:"* ]]
[[ "$output" != *"show_help: command not found"* ]]
}
Loading