-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
226 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...i/langstream/runtime/impl/k8s/agents/vectors/AstraVectorDBVectorDatabaseWriterConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright DataStax, Inc. | ||
* | ||
* 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. | ||
*/ | ||
package ai.langstream.runtime.impl.k8s.agents.vectors; | ||
|
||
import ai.langstream.api.doc.AgentConfig; | ||
import ai.langstream.api.doc.ConfigProperty; | ||
import ai.langstream.runtime.impl.k8s.agents.QueryVectorDBAgentProvider; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.util.List; | ||
import lombok.Data; | ||
|
||
@Data | ||
@AgentConfig( | ||
name = "Astra Vector DB", | ||
description = | ||
""" | ||
Writes data to Apache Cassandra. | ||
All the options from DataStax Kafka Sink are supported: https://docs.datastax.com/en/kafka/doc/kafka/kafkaConfigTasksTOC.html | ||
""") | ||
public class AstraVectorDBVectorDatabaseWriterConfig | ||
extends QueryVectorDBAgentProvider.VectorDatabaseWriterConfig { | ||
|
||
public static final QueryVectorDBAgentProvider.VectorDatabaseWriterConfig INSTANCE = | ||
new AstraVectorDBVectorDatabaseWriterConfig(); | ||
|
||
@Override | ||
public Class getAgentConfigModelClass() { | ||
return AstraVectorDBVectorDatabaseWriterConfig.class; | ||
} | ||
|
||
@Override | ||
public boolean isAgentConfigModelAllowUnknownProperties() { | ||
return true; | ||
} | ||
|
||
@ConfigProperty( | ||
description = | ||
"The name of the collection to write to. The collection must already exist.", | ||
required = true) | ||
@JsonProperty("collection-name") | ||
String collectionName; | ||
|
||
@Data | ||
public static class CollectionField { | ||
|
||
@ConfigProperty(description = "Field name", required = true) | ||
String name; | ||
|
||
@ConfigProperty( | ||
description = "JSTL Expression for computing the field value.", | ||
required = true) | ||
String expression; | ||
} | ||
|
||
@ConfigProperty(description = "Fields of the collection to write to.", required = true) | ||
List<CollectionField> fields; | ||
} |
134 changes: 134 additions & 0 deletions
134
...stream-runtime-impl/src/test/java/ai/langstream/kafka/AstraVectorDBAssetQueryWriteIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* Copyright DataStax, Inc. | ||
* | ||
* 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. | ||
*/ | ||
package ai.langstream.kafka; | ||
|
||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.Map; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.kafka.clients.producer.KafkaProducer; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@Slf4j | ||
@Disabled | ||
class AstraVectorDBAssetQueryWriteIT extends AbstractKafkaApplicationRunner { | ||
|
||
static final String SECRETS_PATH = ""; | ||
|
||
@Test | ||
public void testAstra() throws Exception { | ||
String tenant = "tenant"; | ||
String[] expectedAgents = {"app-step1"}; | ||
|
||
String secrets = Files.readString(Paths.get(SECRETS_PATH)); | ||
|
||
Map<String, String> application = | ||
Map.of( | ||
"configuration.yaml", | ||
""" | ||
configuration: | ||
resources: | ||
- type: "vector-database" | ||
name: "AstraDBDatasource" | ||
configuration: | ||
service: "astra-vector-db" | ||
token: "${ secrets.astra.token }" | ||
endpoint: "${ secrets.astra.endpoint }" | ||
""", | ||
"pipeline.yaml", | ||
""" | ||
assets: | ||
- name: "documents-collection" | ||
asset-type: "astra-collection" | ||
creation-mode: create-if-not-exists | ||
deletion-mode: delete | ||
config: | ||
collection-name: "documents" | ||
datasource: "AstraDBDatasource" | ||
vector-dimension: 3 | ||
topics: | ||
- name: "input-topic" | ||
creation-mode: create-if-not-exists | ||
pipeline: | ||
- id: step1 | ||
name: "Write a document using a query" | ||
type: "query-vector-db" | ||
input: "input-topic" | ||
configuration: | ||
mode: execute | ||
datasource: "AstraDBDatasource" | ||
query: | | ||
{ | ||
"action": "insertOne", | ||
"collection-name": "documents", | ||
"document": { | ||
"id": "the-id", | ||
"name": "A name", | ||
"text": "A text", | ||
"vector": [1,2,3] | ||
} | ||
} | ||
output-field: "value.insertresult" | ||
fields: | ||
- "value.documentId" | ||
- name: "Read the document using a query" | ||
type: "query-vector-db" | ||
configuration: | ||
datasource: "AstraDBDatasource" | ||
query: | | ||
{ | ||
"collection-name": "documents", | ||
"filter": { | ||
"id": ? | ||
}, | ||
"vector": [1,2,3] | ||
} | ||
only-first: true | ||
output-field: "value.queryresult" | ||
fields: | ||
- "value.insertresult.id" | ||
- id: step2 | ||
name: "Write a new record to Astra" | ||
type: "vector-db-sink" | ||
configuration: | ||
datasource: "AstraDBDatasource" | ||
collection-name: "documents" | ||
fields: | ||
- name: "id" | ||
expression: "fn:toString('new-id')" | ||
- name: "vector" | ||
expression: "value.queryresult.vector" | ||
- name: "text" | ||
expression: "value.queryresult.text" | ||
- name: "name" | ||
expression: "value.queryresult.name" | ||
"""); | ||
|
||
try (ApplicationRuntime applicationRuntime = | ||
deployApplicationWithSecrets( | ||
tenant, "app", application, buildInstanceYaml(), secrets, expectedAgents)) { | ||
try (KafkaProducer<String, String> producer = createProducer(); ) { | ||
|
||
sendMessage("input-topic", "{\"documentId\":1}", producer); | ||
|
||
executeAgentRunners(applicationRuntime); | ||
} | ||
|
||
applicationDeployer.cleanup(tenant, applicationRuntime.implementation()); | ||
} | ||
} | ||
} |