Call PutDataPipelineConfiguration by using OSS Go SDK V2 to create a data pipeline (DataPipeline) rule. After the rule is created, OSS automatically calls Alibaba Cloud Model Studio to vectorize the raw data in the source bucket and writes the vectors to the specified index in the vector bucket.
Prerequisites
OSS Go SDK V2 is installed. You can install it by running
go get github.com/aliyun/alibabacloud-oss-go-sdk-v2.Access credentials are configured through environment variables. The examples in this topic use
credentials.NewEnvironmentVariableCredentialsProvider()to read credentials from theOSS_ACCESS_KEY_IDandOSS_ACCESS_KEY_SECRETenvironment variables.
Sample code
package main
import (
"context"
"log"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/dataprocess"
)
func main() {
region := "cn-hangzhou"
role := "acs:ram::<AccountId>:role/my-data-pipeline-role"
apiKey := "sk-xxxx"
dataPipelineName := "my-data-pipeline"
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region)
client := dataprocess.NewClient(cfg)
result, err := client.PutDataPipelineConfiguration(context.TODO(), &dataprocess.PutDataPipelineConfigurationRequest{
DataPipelineName: oss.Ptr(dataPipelineName),
Role: oss.Ptr(role),
DataPipelineConfiguration: &dataprocess.DataPipelineConfiguration{
DataPipelineDescription: oss.Ptr("Vectorize business data using the BERT multimodal model"),
Sources: []dataprocess.DataPipelineSource{
{
InputBucket: oss.Ptr("bucket"),
InputDataScope: oss.Ptr("All"),
FilterConfiguration: &dataprocess.DataPipelineSourceFilterConfiguration{
PrefixSet: []string{"prefix1"},
ObjectMediaTypes: []string{"text"},
},
},
},
DataPipelineEmbeddingConfiguration: &dataprocess.DataPipelineEmbeddingConfiguration{
ApiKey: oss.Ptr(apiKey),
EmbeddingProvider: oss.Ptr("bailian"),
FPS: oss.Ptr(float64(1)),
Model: oss.Ptr("qwen2.5-vl-embedding"),
},
Destination: &dataprocess.DataPipelineDestination{
VectorBucketName: oss.Ptr("my-vector-bucket"),
VectorIndexNames: []string{"index"},
VectorKeyPrefix: oss.Ptr("prefix"),
ObjectTagToMetadata: []string{"key1"},
UsermetaToMetadata: []string{"x-oss-meta-key1"},
},
DataPipelineError: &dataprocess.DataPipelineError{
ErrorMode: oss.Ptr("ignoreAndRecord"),
ErrorBucket: oss.Ptr("my-error-bucket"),
ErrorPrefix: oss.Ptr("error-output/"),
},
},
})
if err != nil {
log.Fatalf("failed to put pipeline configuration %v", err)
}
log.Printf("put pipeline configuration result:%#v\n", result)
}
References
For the complete sample code, see put_data_pipeline_configuration.go.
该文章对您有帮助吗?