{"cells": [{"attachments": {}, "cell_type": "markdown", "id": "e6766aaf", "metadata": {}, "source": ["\"Open\n"]}, {"cell_type": "markdown", "id": "f3ca56f0-6ef1-426f-bac5-fd7c374d0f51", "metadata": {}, "source": ["# Qdrant Reader\n"]}, {"cell_type": "code", "execution_count": null, "id": "fc527b72", "metadata": {}, "outputs": [], "source": ["%pip install llama-index-readers-qdrant"]}, {"cell_type": "code", "execution_count": null, "id": "778ee662", "metadata": {}, "outputs": [], "source": ["import logging\n", "import sys\n", "\n", "logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n", "logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))"]}, {"attachments": {}, "cell_type": "markdown", "id": "3ccaf16b", "metadata": {}, "source": ["如果您在colab上打开这个笔记本,您可能需要安装LlamaIndex 🦙。\n"]}, {"cell_type": "code", "execution_count": null, "id": "372536d8", "metadata": {}, "outputs": [], "source": ["!pip install llama-index"]}, {"cell_type": "code", "execution_count": null, "id": "262f990a-79c8-413a-9f3c-cd9a3c191307", "metadata": {}, "outputs": [], "source": ["from llama_index.readers.qdrant import QdrantReader"]}, {"cell_type": "code", "execution_count": null, "id": "252f8163-7297-44b6-a838-709e9662f3d6", "metadata": {}, "outputs": [], "source": ["reader = QdrantReader(host=\"localhost\")"]}, {"cell_type": "code", "execution_count": null, "id": "53b49187-8477-436c-9718-5d2f8cc6fad0", "metadata": {}, "outputs": [], "source": ["# 查询向量是查询的嵌入表示\n", "# 示例查询向量:\n", "# query_vector=[0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]\n", "\n", "query_vector = [n1, n2, n3, ...]"]}, {"cell_type": "code", "execution_count": null, "id": "a88be1c4-603f-48b9-ac64-10a219af4951", "metadata": {}, "outputs": [], "source": ["# 注意:必需参数为 collection_name, query_vector。\n", "# 请参阅 Python 客户端:https://github.com/qdrant/qdrant_client\n", "# 了解更多细节。\n", "documents = reader.load_data(\n", " collection_name=\"demo\", query_vector=query_vector, limit=5\n", ")"]}, {"cell_type": "markdown", "id": "169b4273-eb20-4d06-9ffe-71320f4570f6", "metadata": {}, "source": ["### 创建索引\n"]}, {"cell_type": "code", "execution_count": null, "id": "ac4563a1", "metadata": {}, "outputs": [], "source": ["index = SummaryIndex.from_documents(documents)"]}, {"cell_type": "code", "execution_count": null, "id": "f06b02db", "metadata": {}, "outputs": [], "source": ["# 将日志级别设置为DEBUG,以获得更详细的输出\n", "query_engine = index.as_query_engine()\n", "response = query_engine.query(\"\")"]}, {"cell_type": "code", "execution_count": null, "id": "97d1ae80", "metadata": {}, "outputs": [], "source": ["display(Markdown(f\"{response}\"))"]}], "metadata": {"kernelspec": {"display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3"}}, "nbformat": 4, "nbformat_minor": 5}