Skip to content
Merged
7 changes: 7 additions & 0 deletions agentscope-distribution/agentscope-all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>io.agentscope</groupId>
<artifactId>agentscope-extensions-rag-haystack</artifactId>
<scope>compile</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>io.agentscope</groupId>
<artifactId>agentscope-extensions-rag-simple</artifactId>
Expand Down
7 changes: 7 additions & 0 deletions agentscope-distribution/agentscope-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@
<version>${project.version}</version>
</dependency>

<!-- AgentScope Extensions Rag HayStack -->
<dependency>
<groupId>io.agentscope</groupId>
<artifactId>agentscope-extensions-rag-haystack</artifactId>
<version>${project.version}</version>
</dependency>

<!-- AgentScope Extensions Rag Simple -->
<dependency>
<groupId>io.agentscope</groupId>
Expand Down
5 changes: 5 additions & 0 deletions agentscope-examples/quickstart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
<artifactId>agentscope-extensions-rag-ragflow</artifactId>
</dependency>

<dependency>
<groupId>io.agentscope</groupId>
<artifactId>agentscope-extensions-rag-haystack</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright 2024-2025 the original author or authors.
*
* Licensed 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
*
* https://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 io.agentscope.examples.quickstart;

import io.agentscope.core.ReActAgent;
import io.agentscope.core.agent.user.UserAgent;
import io.agentscope.core.message.Msg;
import io.agentscope.core.model.DashScopeChatModel;
import io.agentscope.core.rag.RAGMode;
import io.agentscope.core.rag.integration.haystack.HayStackConfig;
import io.agentscope.core.rag.integration.haystack.HayStackKnowledge;
import io.agentscope.core.rag.model.RetrieveConfig;

/**
* Example demonstrating how to use HayStack Knowledge Base for RAG.
*/
public class HayStackRAGExample {

public static void main(String[] args) throws Exception {
// Check environment variables
String haystackBaseUrl = System.getenv("HAYSTACK_BASE_URL");
String apiKey = ExampleUtils.getDashScopeApiKey();

if (haystackBaseUrl == null) {
System.err.println("Error: Required environment variables not set.");
System.err.println("Please set the following environment variables:");
System.err.println(" - HAYSTACK_BASE_URL");
System.exit(1);
}

ReActAgent agent =
ReActAgent.builder()
.name("KnowledgeAssistant")
.model(
DashScopeChatModel.builder()
.apiKey(apiKey)
.modelName("qwen-plus")
.build())
.knowledge(
HayStackKnowledge.builder()
.config(
HayStackConfig.builder()
.baseUrl(haystackBaseUrl)
.scoreThreshold(0.2)
.topK(3)
.build())
.build())
.retrieveConfig(RetrieveConfig.builder().scoreThreshold(0.2).build())
.ragMode(RAGMode.GENERIC)
.build();

UserAgent userAgent = UserAgent.builder().name("User").build();

Msg msg = null;
while (true) {
msg = userAgent.call(msg).block();
if (msg.getTextContent().equals("exit")) {
break;
}
msg = agent.call(msg).block();
}
}
}
97 changes: 97 additions & 0 deletions agentscope-extensions/agentscope-extensions-rag-haystack/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2024-2025 the original author or authors.
~
~ Licensed 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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.agentscope</groupId>
<artifactId>agentscope-extensions</artifactId>
<version>${revision}</version>
<relativePath>../pom.xml</relativePath>
</parent>

<name>AgentScope Java - Extensions - RAG - HayStack</name>
<description>AgentScope Extensions - HayStack RAG Integration</description>
<artifactId>agentscope-extensions-rag-haystack</artifactId>

<dependencies>
<!-- AgentScope Core -->
<dependency>
<groupId>io.agentscope</groupId>
<artifactId>agentscope-core</artifactId>
<optional>true</optional>
<scope>provided</scope>
</dependency>

<!-- HTTP Client: OkHttp -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-jvm</artifactId>
</dependency>

<!-- JSON Processing: Jackson (from parent) -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>

<!-- Reactive Programming: Reactor (from core) -->
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</dependency>

<!-- Logging: SLF4J (from core) -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>

<!-- Mock Web Server for Testing -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>mockwebserver</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2024-2025 the original author or authors.
*
* Licensed 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
*
* https://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 io.agentscope.core.rag.integration.haystack;

/**
* Policy to determine how filters are applied in retrievers interacting with document stores.
*/
public enum FilterPolicy {

/**
* Runtime filters replace init filters during retriever run invocation.
*/
REPLACE("replace"),

/**
* Runtime filters are merged with init filters, with runtime filters overwriting init values.
*/
MERGE("merge");

private final String policy;

FilterPolicy(String policy) {
this.policy = policy;
}

public String getPolicy() {
return policy;
}
}
Loading
Loading