Update utils.py
Browse files
utils.py
CHANGED
@@ -5,9 +5,6 @@ import pinecone
|
|
5 |
import asyncio
|
6 |
from langchain.document_loaders.sitemap import SitemapLoader
|
7 |
|
8 |
-
|
9 |
-
#Function to fetch data from website
|
10 |
-
#https://python.langchain.com/docs/modules/data_connection/document_loaders/integrations/sitemap
|
11 |
def get_website_data(sitemap_url):
|
12 |
|
13 |
loop = asyncio.new_event_loop()
|
@@ -20,7 +17,6 @@ def get_website_data(sitemap_url):
|
|
20 |
|
21 |
return docs
|
22 |
|
23 |
-
#Function to split data into smaller chunks
|
24 |
def split_data(docs):
|
25 |
|
26 |
text_splitter = RecursiveCharacterTextSplitter(
|
@@ -32,13 +28,11 @@ def split_data(docs):
|
|
32 |
docs_chunks = text_splitter.split_documents(docs)
|
33 |
return docs_chunks
|
34 |
|
35 |
-
#Function to create embeddings instance
|
36 |
def create_embeddings():
|
37 |
|
38 |
embeddings = SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")
|
39 |
return embeddings
|
40 |
|
41 |
-
#Function to push data to Pinecone
|
42 |
def push_to_pinecone(pinecone_apikey,pinecone_environment,pinecone_index_name,embeddings,docs):
|
43 |
|
44 |
pinecone.init(
|
@@ -50,7 +44,6 @@ def push_to_pinecone(pinecone_apikey,pinecone_environment,pinecone_index_name,em
|
|
50 |
index = Pinecone.from_documents(docs, embeddings, index_name=index_name)
|
51 |
return index
|
52 |
|
53 |
-
#Function to pull index data from Pinecone
|
54 |
def pull_from_pinecone(pinecone_apikey,pinecone_environment,pinecone_index_name,embeddings):
|
55 |
|
56 |
pinecone.init(
|
@@ -63,7 +56,6 @@ def pull_from_pinecone(pinecone_apikey,pinecone_environment,pinecone_index_name,
|
|
63 |
index = Pinecone.from_existing_index(index_name, embeddings)
|
64 |
return index
|
65 |
|
66 |
-
#This function will help us in fetching the top relevent documents from our vector store - Pinecone Index
|
67 |
def get_similar_docs(index,query,k=2):
|
68 |
|
69 |
similar_docs = index.similarity_search(query, k=k)
|
|
|
5 |
import asyncio
|
6 |
from langchain.document_loaders.sitemap import SitemapLoader
|
7 |
|
|
|
|
|
|
|
8 |
def get_website_data(sitemap_url):
|
9 |
|
10 |
loop = asyncio.new_event_loop()
|
|
|
17 |
|
18 |
return docs
|
19 |
|
|
|
20 |
def split_data(docs):
|
21 |
|
22 |
text_splitter = RecursiveCharacterTextSplitter(
|
|
|
28 |
docs_chunks = text_splitter.split_documents(docs)
|
29 |
return docs_chunks
|
30 |
|
|
|
31 |
def create_embeddings():
|
32 |
|
33 |
embeddings = SentenceTransformerEmbeddings(model_name="all-MiniLM-L6-v2")
|
34 |
return embeddings
|
35 |
|
|
|
36 |
def push_to_pinecone(pinecone_apikey,pinecone_environment,pinecone_index_name,embeddings,docs):
|
37 |
|
38 |
pinecone.init(
|
|
|
44 |
index = Pinecone.from_documents(docs, embeddings, index_name=index_name)
|
45 |
return index
|
46 |
|
|
|
47 |
def pull_from_pinecone(pinecone_apikey,pinecone_environment,pinecone_index_name,embeddings):
|
48 |
|
49 |
pinecone.init(
|
|
|
56 |
index = Pinecone.from_existing_index(index_name, embeddings)
|
57 |
return index
|
58 |
|
|
|
59 |
def get_similar_docs(index,query,k=2):
|
60 |
|
61 |
similar_docs = index.similarity_search(query, k=k)
|