作者:来自 Elastic Kapil Jadhav, Brendan Jugan 及 Ranjana Devaji
semantic_text 现在默认使用 Elastic Inference Service 上的 jina-embeddings-v5-text,从而在 Elasticsearch 中实现多语言 语义搜索 。
动手体验 Elasticsearch:深入探索 Elasticsearch Labs 仓库中的示例 notebooks,开始免费的云试用,或立即在本地机器上试用 Elastic。
今天,我们很高兴地宣布,semantic_text 现在默认使用 Elastic Inference Service(EIS)上的 jina-embeddings-v5-text 系列,无需额外配置即可实现内置的多语言 推理 。
EIS 提供托管的、GPU 加速的推理,并与 Elasticsearch 紧密集成。使用 EIS,你无需为 embedding 模型托管、扩展或维护基础设施。
语义搜索基于语义检索结果。文本会被转换为向量 embedding,使查询即使在用词不同的情况下也能匹配相关概念。
semantic_text 字段类型简化了整个流程:在索引时自动分块、生成 embedding,并通过 semantic query 无缝查询,无需构建自定义 pipeline 或管理独立的模型推理。
jina-embeddings -v5-text 模型系列刚刚在 EIS 上发布,使开发者能够在核心 semantic_text 工作流中直接使用强大的多语言 embedding。因此,现在你的语义搜索开箱即支持跨语言能力,全球数据集(如支持文章、产品描述、用户评论和多语言网站)无需额外配置即可使用。
这一默认设置在无需运维开销的情况下,实现了覆盖全球的语义检索能力。
jina-embeddings-v5-text
jina-embeddings-v5-text 模型代表了 EIS 上最新一代紧凑且高性能的多语言 embedding 模型。
- 最先进的多语言性能:在 MMTEB 基准测试中,在数百种语言上获得顶级分数。jina-embeddings-v5-text-nano 在 500M 参数以下模型中领先,而 jina-embeddings-v5-text-small 明显优于更大规模的替代方案。
- 多任务能力:涵盖检索、语义匹配、聚类和分类等任务。
- 灵活选择以适配你的使用场景:提供两种模型尺寸(small、nano),可在速度、成本和质量之间平衡。
- 长上下文支持:高效处理长文本 embedding,非常适合具有扩展上下文的文档集合。
开始使用
1)创建索引
定义一个 semantic_text 字段,无需额外配置。embedding 会在索引时使用默认模型自动生成。对于生产工作负载,建议显式指定模型,以确保行为和结果的一致性。
`
1. PUT /multilingual-reviews
2. {
3. "mappings": {
4. "properties": {
5. "product": { "type": "keyword" },
6. "review": { "type": "semantic_text" },
7. "language": { "type": "keyword" }
8. }
9. }
10. }
`AI写代码
索引多语言文档
添加六种不同语言的产品评论。每个文档的 review 字段会在摄取时自动生成 embedding,无需单独的 pipeline 或预处理。
`
1. POST /multilingual-reviews/_bulk?refresh=wait_for
2. { "index": { "_id": "1" } }
3. { "product": "wireless-headphones", "review": "Amazing noise cancellation and the battery lasts all day. Perfect for long flights.", "language": "en" }
4. { "index": { "_id": "2" } }
5. { "product": "wireless-headphones", "review": "La cancelación de ruido es impresionante. Muy cómodos incluso después de horas de uso.", "language": "es" }
6. { "index": { "_id": "3" } }
7. { "product": "wireless-headphones", "review": "ノイズキャンセリングが素晴らしく、長時間つけていても耳が痛くなりません。", "language": "ja" }
8. { "index": { "_id": "4" } }
9. { "product": "wireless-headphones", "review": "Réduction de bruit excellente et très confortable pour les longs trajets en avion.", "language": "fr" }
10. { "index": { "_id": "5" } }
11. { "product": "wireless-headphones", "review": "Hervorragende Geräuschunterdrückung. Ideal für Pendler und Vielflieger.", "language": "de" }
12. { "index": { "_id": "6" } }
13. { "product": "wireless-headphones", "review": "O cancelamento de ruído é excelente e a bateria dura o dia todo.", "language": "pt" }
`AI写代码
3)使用英文查询实现跨语言搜索
`
1. GET /multilingual-reviews/_search
2. {
3. "query": {
4. "match": {
5. "review": "comfortable for long flights"
6. }
7. }
8. }
`AI写代码
结果显示所有六条评论按照与英文查询的语义相关性进行排序:
`
1. {
2. "took": 83,
3. "timed_out": false,
4. "_shards": {
5. "total": 6,
6. "successful": 6,
7. "skipped": 0,
8. "failed": 0
9. },
10. "hits": {
11. "total": {
12. "value": 6,
13. "relation": "eq"
14. },
15. "max_score": 0.8275735,
16. "hits": [
17. {
18. "_index": "multilingual-reviews",
19. "_id": "4",
20. "_score": 0.8275735,
21. "_source": {
22. "product": "wireless-headphones",
23. "review": "Réduction de bruit excellente et très confortable pour les longs trajets en avion.",
24. "language": "fr"
25. }
26. },
27. {
28. "_index": "multilingual-reviews",
29. "_id": "1",
30. "_score": 0.7616198,
31. "_source": {
32. "product": "wireless-headphones",
33. "review": "Amazing noise cancellation and the battery lasts all day. Perfect for long flights.",
34. "language": "en"
35. }
36. },
37. {
38. "_index": "multilingual-reviews",
39. "_id": "5",
40. "_score": 0.72122526,
41. "_source": {
42. "product": "wireless-headphones",
43. "review": "Hervorragende Geräuschunterdrückung. Ideal für Pendler und Vielflieger.",
44. "language": "de"
45. }
46. },
47. {
48. "_index": "multilingual-reviews",
49. "_id": "2",
50. "_score": 0.6867013,
51. "_source": {
52. "product": "wireless-headphones",
53. "review": "La cancelación de ruido es impresionante. Muy cómodos incluso después de horas de uso.",
54. "language": "es"
55. }
56. },
57. {
58. "_index": "multilingual-reviews",
59. "_id": "3",
60. "_score": 0.66513836,
61. "_source": {
62. "product": "wireless-headphones",
63. "review": "ノイズキャンセリングが素晴らしく、長時間つけていても耳が痛くなりません。",
64. "language": "ja"
65. }
66. },
67. {
68. "_index": "multilingual-reviews",
69. "_id": "6",
70. "_score": 0.61658823,
71. "_source": {
72. "product": "wireless-headphones",
73. "review": "O cancelamento de ruído é excelente e a bateria dura o dia todo.",
74. "language": "pt"
75. }
76. }
77. ]
78. }
79. }
`AI写代码收起代码块
请注意,法语评论排名第一,甚至高于英文评论。这是因为“très confortable pour les longs trajets en avion”(“非常适合长时间飞机旅行,十分舒适”)在语义上比英文评论更接近查询,而英文评论将重点分散在降噪、电池续航和飞行等方面。这展示了 jina-embeddings-v5-text-small 按语义而非语言进行排序的能力。
4)使用日文查询实现跨语言搜索
`
1. GET /multilingual-reviews/_search
2. {
3. "query": {
4. "match": {
5. "review": "長時間のフライトに最適"
6. }
7. }
8. }
`AI写代码
结果显示所有六条评论按照与日文查询(“Ideal for long-haul flights”)的语义相关性进行排序:
`
1. {
2. "took": 89,
3. "timed_out": false,
4. "_shards": {
5. "total": 6,
6. "successful": 6,
7. "skipped": 0,
8. "failed": 0
9. },
10. "hits": {
11. "total": {
12. "value": 6,
13. "relation": "eq"
14. },
15. "max_score": 0.7556782,
16. "hits": [
17. {
18. "_index": "multilingual-reviews",
19. "_id": "4",
20. "_score": 0.7556782,
21. "_source": {
22. "product": "wireless-headphones",
23. "review": "Réduction de bruit excellente et très confortable pour les longs trajets en avion.",
24. "language": "fr"
25. }
26. },
27. {
28. "_index": "multilingual-reviews",
29. "_id": "1",
30. "_score": 0.7395687,
31. "_source": {
32. "product": "wireless-headphones",
33. "review": "Amazing noise cancellation and the battery lasts all day. Perfect for long flights.",
34. "language": "en"
35. }
36. },
37. {
38. "_index": "multilingual-reviews",
39. "_id": "5",
40. "_score": 0.68835545,
41. "_source": {
42. "product": "wireless-headphones",
43. "review": "Hervorragende Geräuschunterdrückung. Ideal für Pendler und Vielflieger.",
44. "language": "de"
45. }
46. },
47. {
48. "_index": "multilingual-reviews",
49. "_id": "3",
50. "_score": 0.6487931,
51. "_source": {
52. "product": "wireless-headphones",
53. "review": "ノイズキャンセリングが素晴らしく、長時間つけていても耳が痛くなりません。",
54. "language": "ja"
55. }
56. },
57. {
58. "_index": "multilingual-reviews",
59. "_id": "6",
60. "_score": 0.6241487,
61. "_source": {
62. "product": "wireless-headphones",
63. "review": "O cancelamento de ruído é excelente e a bateria dura o dia todo.",
64. "language": "pt"
65. }
66. },
67. {
68. "_index": "multilingual-reviews",
69. "_id": "2",
70. "_score": 0.6183049,
71. "_source": {
72. "product": "wireless-headphones",
73. "review": "La cancelación de ruido es impresionante. Muy cómodos incluso después de horas de uso.",
74. "language": "es"
75. }
76. }
77. ]
78. }
79. }
`AI写代码收起代码块
排名几乎与英文查询相同:法语和英语仍然领先,因为它们在语义上与“非常适合长途飞行”最相关,而不受查询语言影响。日语评论不会因为查询是日语而被人为提升。它排名第四,因为内容讨论的是佩戴舒适性,而不是飞行。语义相关性优先于语言匹配。
注意:对于仅使用英文的场景
如果你更倾向于稀疏表示,或希望继续在英文工作负载中使用 Elastic Learned Sparse EncodeR(ELSER),ELSER 仍然可用并受到完全支持,可作为 semantic_text 的一种选项。
在创建索引时,你可以通过在 mappings 中指定 inference_id: "elser" 来显式选择 ELSER。
结论:无边界的语义搜索
随着 semantic_text 现在默认使用 Elastic Inference Service 上的 jina-embeddings-v5-text 系列,多语言语义搜索已成为 Elasticsearch 中的标准开发体验。这意味着开发者可以构建跨全球数据集运行的搜索、检索增强生成(retrieval augmented generation - RAG)和 AI 应用,而无需拼接各种 pipeline。
创建一个 semantic_text 字段,索引你的数据,然后开始搜索。所有 Elastic Cloud 试用都可以访问 Elastic Inference Service。现在就可以在 Elastic Cloud Serverless 或 Elastic Cloud Hosted 上试用,或者通过 Cloud Connect 在你的自管理集群中使用 EIS。