1414from langchain .text_splitter import RecursiveCharacterTextSplitter
1515from langchain_community .document_loaders .pdf import PyPDFLoader
1616from langchain_openai import OpenAIEmbeddings
17- from langchain_pinecone import PineconeVectorStore as LCPinecone
17+ from langchain_pinecone import PineconeVectorStore
1818
1919# pinecone integration
2020# import pinecone
2121from pinecone import Pinecone , ServerlessSpec
2222from pinecone .core .client .exceptions import PineconeApiException
23+ from pinecone .models import IndexList
2324
2425# this project
2526from models .conf import settings
2829logging .basicConfig (level = logging .DEBUG if settings .debug_mode else logging .ERROR )
2930
3031
31- # pylint: disable=too-few-public-methods
32- # class TextSplitter:
33- # """
34- # Custom text splitter that adds metadata to the Document object
35- # which is required by PineconeHybridSearchRetriever.
36- # """
37-
38- # def create_documents(self, texts):
39- # """Create documents"""
40- # documents = []
41- # for text in texts:
42- # # Create a Document object with the text and metadata
43- # document = Document(page_content=text, metadata={"context": text})
44- # documents.append(document)
45- # return documents
46-
47-
4832class PineconeIndex :
4933 """Pinecone helper class."""
5034
@@ -53,7 +37,7 @@ class PineconeIndex:
5337 _index_name : str = None
5438 _text_splitter : RecursiveCharacterTextSplitter = None
5539 _openai_embeddings : OpenAIEmbeddings = None
56- _vector_store : LCPinecone = None
40+ _vector_store : PineconeVectorStore = None
5741
5842 def __init__ (self , index_name : str = None ):
5943 self .init ()
@@ -92,15 +76,15 @@ def index_stats(self) -> dict:
9276 def initialized (self ) -> bool :
9377 """initialized read-only property."""
9478 indexes = self .pinecone .list_indexes ()
95- return self .index_name in indexes
79+ return self .index_name in indexes . names ()
9680
9781 @property
98- def vector_store (self ) -> LCPinecone :
82+ def vector_store (self ) -> PineconeVectorStore :
9983 """Pinecone lazy read-only property."""
10084 if self ._vector_store is None :
10185 if not self .initialized :
10286 self .init_index ()
103- self ._vector_store = LCPinecone (
87+ self ._vector_store = PineconeVectorStore (
10488 index = self .index ,
10589 embedding = self .openai_embeddings ,
10690 text_key = settings .pinecone_vectorstore_text_key ,
@@ -134,8 +118,9 @@ def text_splitter(self) -> RecursiveCharacterTextSplitter:
134118
135119 def init_index (self ):
136120 """Verify that an index named self.index_name exists in Pinecone. If not, create it."""
121+ indexes : IndexList = None
137122 indexes = self .pinecone .list_indexes ()
138- if self .index_name not in indexes :
123+ if self .index_name not in indexes . names () :
139124 logging .debug ("Index does not exist." )
140125 self .create ()
141126
0 commit comments