-
Notifications
You must be signed in to change notification settings - Fork 129
/
ingestion.py
75 lines (58 loc) · 2.81 KB
/
ingestion.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
from dotenv import load_dotenv
load_dotenv()
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_community.document_loaders import ReadTheDocsLoader
from langchain_openai import OpenAIEmbeddings
from langchain_pinecone import PineconeVectorStore
from consts import INDEX_NAME
embeddings = OpenAIEmbeddings(model="text-embedding-3-small")
def ingest_docs():
loader = ReadTheDocsLoader("langchain-docs/api.python.langchain.com/en/latest")
raw_documents = loader.load()
print(f"loaded {len(raw_documents)} documents")
text_splitter = RecursiveCharacterTextSplitter(chunk_size=600, chunk_overlap=50)
documents = text_splitter.split_documents(raw_documents)
for doc in documents:
new_url = doc.metadata["source"]
new_url = new_url.replace("langchain-docs", "https:/")
doc.metadata.update({"source": new_url})
print(f"Going to add {len(documents)} to Pinecone")
PineconeVectorStore.from_documents(documents, embeddings, index_name=INDEX_NAME)
print("****Loading to vectorstore done ***")
def ingest_docs2() -> None:
from langchain_community.document_loaders.firecrawl import FireCrawlLoader
langchain_documents_base_urls = [
"https://python.langchain.com/docs/integrations/chat//",
"https://python.langchain.com/docs/integrations/llms/",
"https://python.langchain.com/docs/integrations/text_embedding/",
"https://python.langchain.com/docs/integrations/document_loaders/",
"https://python.langchain.com/docs/integrations/document_transformers/",
"https://python.langchain.com/docs/integrations/vectorstores/",
"https://python.langchain.com/docs/integrations/retrievers/",
"https://python.langchain.com/docs/integrations/tools/",
"https://python.langchain.com/docs/integrations/stores/",
"https://python.langchain.com/docs/integrations/llm_caching/",
"https://python.langchain.com/docs/integrations/graphs/",
"https://python.langchain.com/docs/integrations/memory/",
"https://python.langchain.com/docs/integrations/callbacks/",
"https://python.langchain.com/docs/integrations/chat_loaders/",
"https://python.langchain.com/docs/concepts/",
]
langchain_documents_base_urls2 = [
"https://python.langchain.com/docs/integrations/chat/"
]
for url in langchain_documents_base_urls2:
print(f"FireCrawling {url=}")
loader = FireCrawlLoader(
url=url,
mode="scrape",
)
docs = loader.load()
print(f"Going to add {len(docs)} documents to Pinecone")
PineconeVectorStore.from_documents(
docs, embeddings, index_name="firecrawl-index"
)
print(f"****Loading {url}* to vectorstore done ***")
if __name__ == "__main__":
ingest_docs2()