Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,6 @@ import re
|
|
3 |
import os
|
4 |
from langchain.chains import ConversationalRetrievalChain
|
5 |
from langchain.document_loaders import WebBaseLoader
|
6 |
-
from langchain.embeddings import SentenceTransformerEmbedding
|
7 |
from langchain.vectorstores import Chroma
|
8 |
from langchain.prompts import load_prompt
|
9 |
from langchain.chat_models import ChatGroq
|
@@ -107,25 +106,8 @@ if st.button("Submit Query"):
|
|
107 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
108 |
splits = text_splitter.split_documents(docs)
|
109 |
|
110 |
-
# Define the embedding class
|
111 |
-
class SentenceTransformerEmbedding:
|
112 |
-
def __init__(self, model_name):
|
113 |
-
self.model = SentenceTransformer(model_name)
|
114 |
-
|
115 |
-
def embed_documents(self, texts):
|
116 |
-
embeddings = self.model.encode(texts, convert_to_tensor=True)
|
117 |
-
if isinstance(embeddings, torch.Tensor):
|
118 |
-
return embeddings.cpu().detach().numpy().tolist() # Convert tensor to list
|
119 |
-
return embeddings
|
120 |
-
|
121 |
-
def embed_query(self, query):
|
122 |
-
embedding = self.model.encode([query], convert_to_tensor=True)
|
123 |
-
if isinstance(embedding, torch.Tensor):
|
124 |
-
return embedding.cpu().detach().numpy().tolist()[0] # Convert tensor to list
|
125 |
-
return embedding[0]
|
126 |
-
|
127 |
# Initialize the embedding model
|
128 |
-
embedding_model =
|
129 |
|
130 |
# Initialize Chroma with the embedding class
|
131 |
vectorstore = Chroma.from_documents(documents=splits, embedding=embedding_model)
|
|
|
3 |
import os
|
4 |
from langchain.chains import ConversationalRetrievalChain
|
5 |
from langchain.document_loaders import WebBaseLoader
|
|
|
6 |
from langchain.vectorstores import Chroma
|
7 |
from langchain.prompts import load_prompt
|
8 |
from langchain.chat_models import ChatGroq
|
|
|
106 |
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
107 |
splits = text_splitter.split_documents(docs)
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
# Initialize the embedding model
|
110 |
+
embedding_model = SentenceTransformer('all-MiniLM-L6-v2')
|
111 |
|
112 |
# Initialize Chroma with the embedding class
|
113 |
vectorstore = Chroma.from_documents(documents=splits, embedding=embedding_model)
|