如果您在 Colab 上打开此 Notebook,可能需要安装 LlamaIndex 🦙。
输入 [ ]
已复制!
%pip install llama-index-embeddings-google
%pip install llama-index-embeddings-google
输入 [ ]
已复制!
!pip install llama-index
!pip install llama-index
输入 [ ]
已复制!
# imports
from llama_index.embeddings.google import GooglePaLMEmbedding
# 导入 from llama_index.embeddings.google import GooglePaLMEmbedding
输入 [ ]
已复制!
# get API key and create embeddings
model_name = "models/embedding-gecko-001"
api_key = "YOUR API KEY"
embed_model = GooglePaLMEmbedding(model_name=model_name, api_key=api_key)
embeddings = embed_model.get_text_embedding("Google PaLM Embeddings.")
# 获取 API 密钥并创建嵌入 model_name = "models/embedding-gecko-001" api_key = "YOUR API KEY" embed_model = GooglePaLMEmbedding(model_name=model_name, api_key=api_key) embeddings = embed_model.get_text_embedding("Google PaLM Embeddings.")
/opt/homebrew/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html from .autonotebook import tqdm as notebook_tqdm
输入 [ ]
已复制!
print(f"Dimension of embeddings: {len(embeddings)}")
print(f"嵌入维度: {len(embeddings)}")
Dimension of embeddings: 768
输入 [ ]
已复制!
embeddings[:5]
embeddings[:5]
输出 [ ]
[0.028517298, -0.0028859433, -0.035110522, 0.021982985, -0.0039763353]