文档

Java SDK快速入门

更新时间:

本文介绍如何使用Java SDK对智能召回引擎进行读写操作。

前提条件

已完成Java SDK安装。更多信息,请参见 安装Java SDK

示例代码

本示例中,初始化智能召回引擎的客户端,并调用接口完成对服务的查询操作,对详情表的写操作。示例如下:

BeClient client = new BeClient("aime-cn-xxxx.aime.aliyuncs.com", 80, "username", "password");

// x2i召回
BeReadRequest x2iRequest = BeReadRequest.builder()
    .bizName("x2i_biz")
    .bizType(BeBizType.X2I)
    .returnCount(10)
    .items(Lists.newArrayList("indexall_common:1"))
    .filter(new FilterClause(new SingleFilter("category_level1", FilterOperator.EQ, "'15'")))
    .build();
BeResponse<BeResult> x2iResponse = client.query(x2iRequest);

// 向量召回
String vector = "-0.5430353283882141,-0.0292476424574852,-0.3608616292476654,-0.35043397545814514,-0.23355364799499512,-0.24787241220474243,0.27063214778900146,-0.40489235520362854,0.3900103271007538,0.54123854637146,-0.006652768235653639,0.26998400688171387,-0.08973824232816696,0.5796284079551697,0.1965138018131256,0.6804714798927307,-0.3605094254016876,-0.12562842667102814,0.543321430683136,0.4717116057872772,-0.30192506313323975,0.2214985191822052,0.1516236513853073,0.21026527881622314,-0.6978874206542969,-0.11705683171749115,0.2574385106563568,-0.3885158896446228,-0.4346419870853424,0.1547151654958725";
BeReadRequest vectorRequest = BeReadRequest.builder()
    .bizName("vector_biz")
    .bizType(BeBizType.VECTOR)
    .returnCount(10)
    .items(Lists.newArrayList(vector))
    .build();
BeResponse<BeResult> vectorResponse = client.query(vectorRequest);

// 写add消息
String tableName = "detail_inc_table";
HashMap<String, String> contents = Maps.newHashMap();
contents.put("id", "1");
contents.put("field1", "value1");
contents.put("field2", "value2");
BeWriteRequest addRequest = BeWriteRequest.builder()
    .type(BeWriteType.ADD)
    .tableName(tableName)
    .contents(contents)
    .build();
BeResponse writeResponse = client.write(addRequest);

// 写delete消息
HashMap<String, String> deleteContents = Maps.newHashMap();
deleteContents.put("id", "1");
BeWriteRequest deleteRequest = BeWriteRequest.builder()
    .type(BeWriteType.DELETE)
    .tableName(tableName)
    .contents(deleteContents)
    .build();
writeResponse = client.write(deleteRequest);
  • 本页导读 (0)