Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError Traceback (most recent call last) <ipython-input-74-15688820a1ef> in <cell line: 3>() 2 file_path="vector_index.pkl" 3 with open(file_path, "wb") as f: ----> 4 pickle.dump(vectorindex_openai, f) TypeError: cannot pickle '_thread.RLock' object #304

Open
UsmanAmeeer opened this issue May 8, 2024 · 0 comments

Comments

@UsmanAmeeer
Copy link

TypeError Traceback (most recent call last)
in <cell line: 3>()
2 file_path="vector_index.pkl"
3 with open(file_path, "wb") as f:
----> 4 pickle.dump(vectorindex_openai, f)

TypeError: cannot pickle '_thread.RLock' object

-- coding: utf-8 --

"""Langchain_LLM.ipynb

Automatically generated by Colaboratory.

Original file is located at
https://colab.research.google.com/drive/1DWToK3XFOM0v5bl7-LwT0GBfKyYVulnb
"""

!pip install python-magic langchain unstructured streamlit openai tiktoken faiss-gpu

import os
import streamlit as st
import pickle
import time
from langchain import OpenAI
from langchain.chains import RetrievalQAWithSourcesChain
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.document_loaders import UnstructuredURLLoader
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores import FAISS

os.environ['OPENAI_API_KEY'] = "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"

llm = OpenAI(temperature = 0.9, max_tokens=500)

loader = UnstructuredURLLoader(
urls = [
"https://www.moneycontrol.com/news/business/banks/hdfc-bank-re-appoints-sanmoy-chakrabarti-as-chief-risk-officer-11259771.html",
"https://www.moneycontrol.com/news/business/markets/market-corrects-post-rbi-ups-inflation-forecast-icrr-bet-on-these-top-10-rate-sensitive-stocks-ideas-11142611.html"
]
)
data = loader.load()
len(data)

data[0].metadata

text_splitter = RecursiveCharacterTextSplitter(
chunk_size = 1000, # size of each chunk created
chunk_overlap = 200, # size of overlap between chunks in order to maintain the context
)
docs = text_splitter.split_documents(data)
len(docs)

docs[2]

Create the embeddings of the chunks using openAIEmbeddings

embeddings = OpenAIEmbeddings()

Pass the documents and embeddings inorder to create FAISS vector index

vectorindex_openai = FAISS.from_documents(docs, embeddings)

Storing vector index create in local

file_path="vector_index.pkl"
with open(file_path, "wb") as f:
pickle.dump(vectorindex_openai, f)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant