sanjam99
commited on
Commit
·
d42b9d4
1
Parent(s):
e110be9
RAG
Browse files
app.py
CHANGED
|
@@ -17,11 +17,17 @@ def load_and_retrieve_docs(url):
|
|
| 17 |
splits = text_splitter.split_documents(docs)
|
| 18 |
embedding_model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
| 19 |
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
vectorstore = Chroma.from_documents(documents=splits, embedding=
|
| 25 |
return vectorstore.as_retriever()
|
| 26 |
|
| 27 |
# Function to format documents
|
|
|
|
| 17 |
splits = text_splitter.split_documents(docs)
|
| 18 |
embedding_model = SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
| 19 |
|
| 20 |
+
# Define a custom embedding function compatible with Chroma's interface
|
| 21 |
+
class CustomEmbeddings:
|
| 22 |
+
def __init__(self, model):
|
| 23 |
+
self.model = model
|
| 24 |
+
|
| 25 |
+
def embed_documents(self, texts):
|
| 26 |
+
return self.model.encode(texts, convert_to_tensor=True).tolist()
|
| 27 |
+
|
| 28 |
+
embeddings = CustomEmbeddings(embedding_model)
|
| 29 |
|
| 30 |
+
vectorstore = Chroma.from_documents(documents=splits, embedding=embeddings)
|
| 31 |
return vectorstore.as_retriever()
|
| 32 |
|
| 33 |
# Function to format documents
|