首页 > 其他分享 >Qdrant用法;Qdrant在langchain里的用法

Qdrant用法;Qdrant在langchain里的用法

时间:2024-04-19 22:57:01浏览次数:19  
标签:name self qdrant collection 用法 client Qdrant langchain query

基础用法这里不再赘述了。直接参照官网。
想看看一些概率可以参考下面两个网站:
1. https://m.elecfans.com/article/2078558.html
2. https://blog.csdn.net/cxs812760493/article/details/135346390

下面说一些在 langchain 可能遇到的问题:

1. 先确定自己 Collections 中向量 的长度不然会提示:

  b'{"status":{"error":"Wrong input: Vector inserting error: expected dim: 100, got 1536"},"time":0.00411009}'

from qdrant_client.models import PointStruct
from qdrant_client import QdrantClient
import uuid
import numpy as np

client = QdrantClient(host="localhost", port=6333)

collection_name = 'my_collection' 

operation_info = client.upsert(
    collection_name=collection_name,
    wait=True,
    points=[ 
        PointStruct(id=str(uuid.uuid4()), vector=np.random.rand(1536), payload={"city": "Berlin"}), 
        PointStruct(id=str(uuid.uuid4()), vector=np.random.rand(1536), payload={"city": "Berlin2"}), 
    ],
)

print(operation_info)

 

2. 向量数据库中数据已经成功插入,用户内容匹配的方法

# 计算嵌入向量
    def generate_embedding(self,query_text):
        openai_client = openai.Client(
            api_key=Keys.MONSTER_API_KEY, base_url=Keys.MONSTER_API_BASE
        )
        embedding_result = openai_client.embeddings.create(
            input=query_text, model="text-embedding-ada-002"
        )
        
        return embedding_result.data[0].embedding
    
    # 从 qdrant 中查询数据
    def qdrant_query(self, query_text):
        try:
            query_vector = self.generate_embedding(query_text)

            result = self.qdrant_client.search(
                collection_name=self.collection_name,
                query_vector=query_vector,
                limit=10,
            )

            # 此处可以做一个简单的计算, 将低于 0.7 的去掉
            # for res in result:
            #     print(res)
            
            return result

        except Exception as e:
            print(f"请稍后重试,异常原因: {e}") 

            # 创建仓库
            self.qdrant_client.recreate_collection(
                collection_name=self.collection_name,
                vectors_config=models.VectorParams(size=1536, distance=models.Distance.COSINE),
            )

            return []

 

3. langchain 文档中都是先处理文件(txt,pdf等)然后再检索的

retriever = qdrant.as_retriever()

 有没有可能是,文件已经插入 Collections 后再检索的办法。我一直没有找到。还是思路不对。



标签:name,self,qdrant,collection,用法,client,Qdrant,langchain,query
From: https://www.cnblogs.com/qk1314/p/18146936

相关文章

  • mysql中last_insert_id()用法
    前言在使用MySQL时,若表中含自增字段(auto_increment类型),则向表中insert一条记录后,可以调用last_insert_id()来获得最近insert的那行记录的自增字段值。但事实上,使用last_insert_id()时有很多注意事项,很容易踩到坑。数据准备CREATETABLE`tb_product`(`id`bigin......
  • 200 Smart的一些关于寄存器和地址相关的用法实例
    累加器200smart有AC0AC1AC2AC3四个累加器,不能作为位访问累加器大小均是32位累加器的数值不会自动清零,中断会保持并重新装载累加器(进入中断时先把原来的值保存起来,退出中断程序后恢复原程序)只有AC1/AC2/AC3可以用作指针AC0不用作指针,不用作间接寻址LDSM0.0......
  • npm link 用法
    1、什么时候使用npmlink?npmlink用来在本地项目和本地npm包之间建立连接,可以在本地进行模块测试。npm包在开发和迭代更新时,不适合直接发布到线上或者直接发布测试版本进行调试,会导致过程繁琐且版本号过多。此时我们就可以使用npmlink命令将包放在no......
  • MyBatis: databaseId的用法
    可以通过databaseId来区分执行的SQL是在MySQL上还是在Oracle上。一、在配置文件mybatis-config中配置databaseId:<?xmlversion="1.0"encoding="UTF-8"?><!DOCTYPEconfigurationPUBLIC"-//mybatis.org//DTDConfig3.0//EN""http://......
  • asan/gpreftools内存调试简明用法
     启用高版本gccsource/opt/rh/devtoolset-11/enable libasan编译选项makeEXTRA_CFLAGS="-O0-g-fsanitize=address-fsanitize-recover=address-fno-omit-frame-pointer-static-libasan-DBUILD_DEBUG-UDPDK_MALLOC-DRTE_MALLOC_ASAN" gpreftools编译选项makeE......
  • .net 6 C#中System.IO.Path类的用法
    1.说明/*PerformsoperationsonSystem.Stringinstancesthatcontainfileordirectorypathinformation.Theseoperationsareperformedinacross-platformmanner.对系统执行操作。包含文件或目录的字符串实例路径信息。这些操作是以跨平台的方式执行的。*/......
  • openai包基础用法
    Note包含同步&异步完成&流式闲言少叙,看剑Requirementspipinstallopenai-UCodeimportopenaiimportasynciodefpp(obj:str):print(obj.center(50,"*"))#syncdef_sync():##w/ostreampp("Syncw/ostream")response......
  • mysql中replace into用法
    前言replaceinto跟insertinto功能类似,不同点在于:replaceinto首先尝试插入数据到表中如果发现表中已经有相同的数据(根据主键或者唯一索引判断)则先删除原来的数据,然后插入新的。否则,直接插入新数据。注意:插入数据的表必须有主键或者是唯一索引!否则的话,replaceinto会......
  • ES6中数组的高级用法
    1.箭头函数和数组方法的结合:使用箭头函数结合数组方法可以简化代码:constnumbers=[1,2,3,4,5];//使用箭头函数的map方法constdoubled=numbers.map((num)=>num*2);console.log(doubled);//输出:[2,4,6,8,10]2.解构赋值和数组方法的结合:constpoi......
  • Python中operator 模块的用法
    operator模块提供了一套与Python的内置运算符对应的高效率函数。1.函数的种类函数包含的种类有:对象的比较运算、逻辑运算、数学运算和序列运算2.比较运算运算函数语法小于lt(a,b)a<b小于等于le(a,b)a<=b大于gt(a,b)a>b大于等于ge(a,b)......