return new RedisVectorStore(config, embeddingClient);
}
复制代码
更方便和推荐的做法是将 RedisVectorStore 创建为一个 Bean。但如果您决定手动创建它,则必须在设置属性之后并在使用客户端之前调用 RedisVectorStore#afterPropertiesSet() 。 您必须明确列出所有元数据字段名称和范例( TAG , TEXT 或 NUMERIC ),用于过滤表达式中使用的任何元数据字段。上面的 withMetadataFields 注册可过滤的元数据字段:范例为 TAG 的 country ,范例为 NUMERIC 的 year 。
然后在您的主代码中,创建一些文档:
List<Document> documents = List.of(
new Document("Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!! Spring AI rocks!!", Map.of("country", "UK", "year", 2020)),
new Document("The World is Big and Salvation Lurks Around the Corner", Map.of()),
new Document("You walk forward facing the past and you turn back toward the future.", Map.of("country", "NL", "year", 2023)));