使用Ollama与Qdrant
Ollama 为特定应用提供专门的嵌入。Ollama 支持多种嵌入模型,使得可以构建检索增强生成(RAG)应用,这些应用将文本提示与现有文档或特定领域的其他数据结合起来。
安装
您可以使用以下 pip 命令安装所需的包:
pip install ollama qdrant-client
集成示例
以下代码假设Ollama可以通过端口11434访问,Qdrant可以通过端口6334访问。
from qdrant_client import QdrantClient, models
import ollama
COLLECTION_NAME = "NicheApplications"
# Initialize Ollama client
oclient = ollama.Client(host="localhost")
# Initialize Qdrant client
qclient = QdrantClient(host="localhost", port=6333)
# Text to embed
text = "Ollama excels in niche applications with specific embeddings"
# Generate embeddings
response = oclient.embeddings(model="llama3.2", prompt=text)
embeddings = response["embedding"]
# Create a collection if it doesn't already exist
if not qclient.collection_exists(COLLECTION_NAME):
qclient.create_collection(
collection_name=COLLECTION_NAME,
vectors_config=models.VectorParams(
size=len(embeddings), distance=models.Distance.COSINE
),
)
# Upload the vectors to the collection along with the original text as payload
qclient.upsert(
collection_name=COLLECTION_NAME,
points=[models.PointStruct(id=1, vector=embeddings, payload={"text": text})],
)
