Skip to content

Commit

Permalink
Merge pull request #278 from Eyobyb/fix/deployment-issue
Browse files Browse the repository at this point in the history
remove embedding
  • Loading branch information
saminegash authored Jan 18, 2024
2 parents bd94091 + 3d4981a commit c4f43a1
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/sherpa_ai/connectors/vectorstores.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,20 @@ class ConversationStore(VectorStore):
def __init__(self, namespace, db, embeddings, text_key):
self.db = db
self.namespace = namespace
self.embeddings = embeddings
self.text_key = text_key

@classmethod
def from_index(cls, namespace, openai_api_key, index_name, text_key="text"):
pinecone.init(api_key=cfg.PINECONE_API_KEY, environment=cfg.PINECONE_ENV)
logger.info(f"Loading index {index_name} from Pinecone")
index = pinecone.Index(index_name)
embeddings = OpenAIEmbeddings(openai_api_key=openai_api_key)
return cls(namespace, index, embeddings, text_key)
embedding = OpenAIEmbeddings(openai_api_key=openai_api_key)
return cls(namespace, index, embedding, text_key)

def add_text(self, text: str, metadata={}) -> str:
metadata[self.text_key] = text
id = str(uuid.uuid4())
embedding = self.embeddings.embed_query(text)
embedding = OpenAIEmbeddings(openai_api_key=cfg.OPENAI_API_KEY).embed_query(text)
doc = {"id": id, "values": embedding, "metadata": metadata}
self.db.upsert(vectors=[doc], namespace=self.namespace)

Expand All @@ -52,7 +51,7 @@ def similarity_search(
filter: Optional[dict] = None,
threshold: float = 0.7,
) -> list[Document]:
query_embedding = self.embeddings.embed_query(text)
query_embedding = OpenAIEmbeddings(openai_api_key=cfg.OPENAI_API_KEY).embed_query(text)
results = self.db.query(
[query_embedding],
top_k=top_k,
Expand All @@ -76,7 +75,7 @@ def _similarity_search_with_relevance_scores(
**kwargs: Any,
) -> List[Tuple[Document, float]]:
logger.debug("query", query)
query_embedding = self.embeddings.embed_query(query)
query_embedding = OpenAIEmbeddings(openai_api_key=cfg.OPENAI_API_KEY).embed_query(query)
results = self.db.query(
[query_embedding],
top_k=k,
Expand Down

0 comments on commit c4f43a1

Please sign in to comment.