Eng-Musa commited on
Commit
72eff51
·
1 Parent(s): 5dc9124

use local embedings

Browse files
clients/__pycache__/groq_client.cpython-312.pyc CHANGED
Binary files a/clients/__pycache__/groq_client.cpython-312.pyc and b/clients/__pycache__/groq_client.cpython-312.pyc differ
 
clients/groq_client.py CHANGED
@@ -4,8 +4,8 @@ from uuid import uuid4
4
  from groq import Groq
5
  from langchain_core.documents import Document
6
 
7
- # CHANGED: Using HuggingFaceEndpointEmbeddings for online API inference
8
- from langchain_huggingface import HuggingFaceEndpointEmbeddings
9
  from langchain_chroma import Chroma
10
  from dotenv import load_dotenv
11
  import random
@@ -106,19 +106,16 @@ class GroqClient:
106
  return []
107
 
108
  def init_vector_store(self, documents):
109
- # CHANGED: Using online HuggingFaceEndpointEmbeddings with API key
110
- # This uses HuggingFace's hosted inference API instead of local model
111
- if not HF_API_KEY:
112
- raise RuntimeError("HF_API_KEY not found in environment")
113
-
114
- embeddings_model = HuggingFaceEndpointEmbeddings(
115
- model="sentence-transformers/all-MiniLM-L6-v2",
116
- huggingfacehub_api_token=HF_API_KEY,
117
  )
118
 
119
  # Clear old data to avoid duplicates
120
  if os.path.exists(CHROMA_PATH):
121
- shutil.rmtree(CHROMA_PATH)
122
 
123
  uuids = [str(uuid4()) for _ in documents]
124
 
@@ -128,7 +125,6 @@ class GroqClient:
128
  persist_directory=CHROMA_PATH,
129
  )
130
 
131
- # CHANGED: This now makes API calls to HuggingFace for embeddings
132
  vector_store.add_documents(documents=documents, ids=uuids)
133
  return vector_store
134
 
 
4
  from groq import Groq
5
  from langchain_core.documents import Document
6
 
7
+ # CHANGED: Using local HuggingFaceEmbeddings instead of online API
8
+ from langchain_huggingface import HuggingFaceEmbeddings
9
  from langchain_chroma import Chroma
10
  from dotenv import load_dotenv
11
  import random
 
106
  return []
107
 
108
  def init_vector_store(self, documents):
109
+ # CHANGED: Using local HuggingFaceEmbeddings instead of online API
110
+ embeddings_model = HuggingFaceEmbeddings(
111
+ model_name="sentence-transformers/all-MiniLM-L6-v2",
112
+ model_kwargs={"device": "cpu"},
113
+ encode_kwargs={"normalize_embeddings": True},
 
 
 
114
  )
115
 
116
  # Clear old data to avoid duplicates
117
  if os.path.exists(CHROMA_PATH):
118
+ shutil.rmtree(CHROMA_PATH, ignore_errors=True)
119
 
120
  uuids = [str(uuid4()) for _ in documents]
121
 
 
125
  persist_directory=CHROMA_PATH,
126
  )
127
 
 
128
  vector_store.add_documents(documents=documents, ids=uuids)
129
  return vector_store
130
 
requirements.txt CHANGED
@@ -5,4 +5,5 @@ python-dotenv
5
  groq
6
  langchain-core
7
  langchain-huggingface
8
- langchain-chroma
 
 
5
  groq
6
  langchain-core
7
  langchain-huggingface
8
+ langchain-chroma
9
+ sentence-transformers