AttrubtError: у модуля «pinecone» нет атрибута «индекс»Python

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 AttrubtError: у модуля «pinecone» нет атрибута «индекс»

Сообщение Anonymous »

Привет, я пытаюсь создать индекс Pinecone и записать в него встроенные в него код, но я продолжаю получать attributeError: модуль «pinecone» не имеет атрибута 'индекс' , я проверил и обнаружил, что его из-за Langchain и Pinecone Version Mathes So Soke Sokd установил меньшую версию Pinecone-client == 2.2.4, что не совсем не работают.import os
from dotenv import load_dotenv,find_dotenv
from langchain.chains import RetrievalQA
from langchain_openai import ChatOpenAI

load_dotenv(find_dotenv(),override=True)

from pinecone import Pinecone, ServerlessSpec # if you're initializing a new index

from dotenv import load_dotenv, find_dotenv

pc = Pinecone()

# loading PDF, DOCX and TXT files as LangChain Documents
def load_document(file):
import os
name, extension = os.path.splitext(file)

if extension == '.pdf':
from langchain.document_loaders import PyPDFLoader
print(f'Loading {file}')
loader = PyPDFLoader(file)
elif extension == '.docx':
from langchain.document_loaders import Docx2txtLoader
print(f'Loading {file}')
loader = Docx2txtLoader(file)
elif extension == '.txt':
# from langchain.document_loaders import TextLoader
from langchain_community.document_loaders import TextLoader
loader = TextLoader(file)
else:
print('Document format is not supported!')
return None

data = loader.load()
return data

data = load_document('file.txt')

def chunk_data(data, chunk_size=256):
from langchain.text_splitter import RecursiveCharacterTextSplitter
text_splitter = RecursiveCharacterTextSplitter(chunk_size=chunk_size, chunk_overlap=0)
chunks = text_splitter.split_documents(data)
return chunks

def insert_or_fetch_embeddings(index_name, chunks):
# importing the necessary libraries and initializing the Pinecone client
import pinecone
from langchain_community.vectorstores import Pinecone
from langchain_openai import OpenAIEmbeddings
from pinecone import ServerlessSpec

pc = pinecone.Pinecone()

embeddings = OpenAIEmbeddings(model='text-embedding-3-small', dimensions=1536) # 512 works as well

# loading from existing index
if index_name in pc.list_indexes().names():
print(f'Index {index_name} already exists. Loading embeddings ... ', end='')
vector_store = Pinecone.from_existing_index(index_name, embeddings)
print('Ok')
else:
# creating the index and embedding the chunks into the index
print(f'Creating index {index_name} and embeddings ...', end='')

# creating a new index
pc.create_index(
name=index_name,
dimension=1536,
metric='cosine',
spec=ServerlessSpec(
cloud="aws",
region="us-east-1"
)
)

# processing the input documents, generating embeddings using the provided `OpenAIEmbeddings` instance,
# inserting the embeddings into the index and returning a new Pinecone vector store object.
vector_store = Pinecone.from_documents(chunks, embeddings, index_name=index_name)
print('Ok')

return vector_store

index_name = 'askadocument'
vector_store = insert_or_fetch_embeddings(index_name=index_name, chunks=chunks)

llm = ChatOpenAI(model="gpt-4.1-mini", temperature=0.3)

retriever = vector_store.as_retriever(search_type='similarity', search_kwargs={'k': 2})

chain = RetrievalQA.from_chain_type(llm=llm, chain_type="stuff", retriever=retriever)

answer = chain.invoke(query)
< /code>
requirements:
openai
langchain
langchain_openai
langchain_experimental
langchainhub
pinecone
python-dotenv
tiktoken
docx2txt
pypdf
pinecone-client==2.2.4
< /code>
p.s: please don't down vote the question.

Подробнее здесь: https://stackoverflow.com/questions/796 ... bute-index
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • AttrubtError: у модуля «pinecone» нет атрибута «индекс»
    Anonymous » » в форуме Python
    0 Ответы
    5 Просмотры
    Последнее сообщение Anonymous
  • ValueError: клиент должен быть экземпляром pinecone.index, Got
    Anonymous » » в форуме Python
    0 Ответы
    82 Просмотры
    Последнее сообщение Anonymous
  • AttrubtError: у модуля «Numpy» нет атрибута «typedict»
    Anonymous » » в форуме Python
    0 Ответы
    9 Просмотры
    Последнее сообщение Anonymous
  • AttrubtError: у модуля «Numpy» нет атрибута «typedict»
    Anonymous » » в форуме Python
    0 Ответы
    8 Просмотры
    Последнее сообщение Anonymous
  • AttrubtError: у модуля 'sst' нет атрибута 'train_reader'
    Anonymous » » в форуме Python
    0 Ответы
    6 Просмотры
    Последнее сообщение Anonymous

Вернуться в «Python»