代码之家  ›  专栏  ›  技术社区  ›  Axen_Rangs

Langchain松果相似性搜索错误:变量“namespace”的类型无效

  •  0
  • Axen_Rangs  · 技术社区  · 2 年前

    我正在尝试使用Pincone现有的索引进行工作相似性搜索。但我在传递查询时遇到以下错误。这只发生在本地机器上。colab一切正常。

    pinecone.core.client.exceptions.ApiTypeError: Invalid type for variable 'namespace'. Required value type is str and passed type was NoneType at ['namespace']
    

    我的实现如下。

    embeddings = OpenAIEmbeddings(
        openai_api_key=openai_api_key,
        model=embedding_model,
    )
    
    pinecone.init(
    api_key=os.getenv("pineconeapikey"),  # find at app.pinecone.io
    environment=os.getenv("pineconeenvironment"),  # next to api key in console
    
    
    
    def data(query):
        """ Ansewer product related questions. Function requires use query"""
        docsearch = Pinecone.from_existing_index(index_name, embeddings)
        answer = docsearch.similarity_search(query)
        return answer
    
    0 回复  |  直到 2 年前
        1
  •  1
  •   Axen_Rangs    2 年前

    问题出在python环境上。我能够在一个新的python环境中正确运行。

        2
  •  0
  •   Rodrigo Vega Moreno    2 年前

    你得到的错误是因为你没有定义 index_name docsearch = Pinecone.from_existing_index 需要一个字符串。若要执行此操作,请实例化 Index 具有 索引名称 .

    试试这个:

    def data(query):
        """ Answer product related questions. Function requires use query"""
        index_name = pinecone.Index("<the-name-of-your-namespace>") #Add this line
        docsearch = Pinecone.from_existing_index(index_name, embeddings)
        answer = docsearch.similarity_search(query)
        return answer
    

    这是LangChain的 documentation on Pinecone .

    推荐文章