主题
如果你在 Colab 中打开这个 Notebook,可能需要先安装 LlamaIndex 🦙。
%pip install llama-index-embeddings-alephalpha1
!pip install llama-index1
# Initialise with your AA token
import os
os.environ["AA_TOKEN"] = "your_token_here"1
2
3
4
2
3
4
使用 luminous-base 嵌入模型。
- representation=“Document”:用于要存入向量数据库的文本(文档)
- representation=“Query”:用于在向量数据库中检索最相关文档的搜索查询
- representation=“Symmetric”:用于聚类、分类、异常检测或可视化任务。
from llama_index.embeddings.alephalpha import AlephAlphaEmbedding
# To customize your token, do this
# otherwise it will lookup AA_TOKEN from your env variable
# embed_model = AlephAlpha(token="<aa_token>")
# with representation='query'
embed_model = AlephAlphaEmbedding(
model="luminous-base",
representation="Query",
)
embeddings = embed_model.get_text_embedding("Hello Aleph Alpha!")
print(len(embeddings))
print(embeddings[:5])1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
representation_enum: SemanticRepresentation.Query
5120
[0.14257812, 2.59375, 0.33203125, -0.33789062, -0.94140625]1
2
3
4
2
3
4
# with representation='Document'
embed_model = AlephAlphaEmbedding(
model="luminous-base",
representation="Document",
)
embeddings = embed_model.get_text_embedding("Hello Aleph Alpha!")
print(len(embeddings))
print(embeddings[:5])1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
representation_enum: SemanticRepresentation.Document
5120
[0.14257812, 2.59375, 0.33203125, -0.33789062, -0.94140625]1
2
3
4
2
3
4