Harshana commited on
Commit
0e197ca
·
1 Parent(s): efa9c6c

add .gitignore and aet env for HF

Browse files
Files changed (3) hide show
  1. .env +2 -2
  2. .gitignore +115 -0
  3. retrievers/custom_retriever.py +27 -13
.env CHANGED
@@ -1,4 +1,4 @@
1
  LLM_PROVIDER=groq
2
- SUPABASE_URL=https://YOUR.supabase.co
3
- SUPABASE_SERVICE_KEY=your-supabase-service-key
4
  SYSTEM_PROMPT_PATH=system_prompt.txt
 
1
  LLM_PROVIDER=groq
2
+ SUPABASE_URL=https://omwpqmtzmybojocamzvn.supabase.co
3
+ SUPABASE_SERVICE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9td3BxbXR6bXlib2pvY2FtenZuIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTc0NzU2MjMwOSwiZXhwIjoyMDYzMTM4MzA5fQ.OuvoIHTPW0PR1TWLDvSdSjGrIGM-cbyRZi1uJSH-T6A
4
  SYSTEM_PROMPT_PATH=system_prompt.txt
.gitignore ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+
7
+ # Distribution / packaging
8
+ .Python
9
+ build/
10
+ develop-eggs/
11
+ dist/
12
+ downloads/
13
+ eggs/
14
+ .eggs/
15
+ lib/
16
+ lib64/
17
+ parts/
18
+ sdist/
19
+ var/
20
+ wheels/
21
+ *.egg-info/
22
+ .installed.cfg
23
+ *.egg
24
+
25
+ # Virtual environments
26
+ venv/
27
+ ENV/
28
+ env/
29
+ .env
30
+ .venv
31
+ env.bak/
32
+ venv.bak/
33
+ .python-version
34
+
35
+ # Unit test / coverage reports
36
+ htmlcov/
37
+ .tox/
38
+ .nox/
39
+ .coverage
40
+ .coverage.*
41
+ .cache
42
+ nosetests.xml
43
+ coverage.xml
44
+ *.cover
45
+ .hypothesis/
46
+ .pytest_cache/
47
+ pytest-*.xml
48
+
49
+ # Jupyter Notebook
50
+ .ipynb_checkpoints
51
+
52
+ # IPython
53
+ profile_default/
54
+ ipython_config.py
55
+
56
+ # Logs
57
+ *.log
58
+ logs/
59
+ log/
60
+
61
+ # IDE specific files
62
+ .idea/
63
+ .vscode/
64
+ *.swp
65
+ *.swo
66
+ *~
67
+ .DS_Store
68
+ .project
69
+ .pydevproject
70
+ .settings/
71
+ .vs/
72
+ *.sublime-project
73
+ *.sublime-workspace
74
+
75
+ # Database
76
+ *.db
77
+ *.rdb
78
+ *.sqlite
79
+ *.sqlite3
80
+
81
+ # Environment variables
82
+ .env
83
+ .env.local
84
+ .env.development.local
85
+ .env.test.local
86
+ .env.production.local
87
+
88
+ # macOS specific
89
+ .DS_Store
90
+ .AppleDouble
91
+ .LSOverride
92
+ Icon
93
+ ._*
94
+ .DocumentRevisions-V100
95
+ .fseventsd
96
+ .Spotlight-V100
97
+ .TemporaryItems
98
+ .Trashes
99
+ .VolumeIcon.icns
100
+ .com.apple.timemachine.donotpresent
101
+
102
+ # AI/model files
103
+ *.h5
104
+ *.pb
105
+ *.onnx
106
+ *.tflite
107
+ *.pt
108
+ *.pth
109
+ *.weights
110
+
111
+ # Temporary files
112
+ tmp/
113
+ temp/
114
+ .tmp
115
+ *.tmp
retrievers/custom_retriever.py CHANGED
@@ -1,21 +1,35 @@
 
 
1
  import os
2
  from langchain_huggingface import HuggingFaceEmbeddings
3
  from langchain_community.vectorstores import SupabaseVectorStore
4
  from supabase.client import create_client
5
  from config import settings
6
 
7
- embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2")
8
- supabase = create_client(settings.supabase_url, settings.supabase_key)
9
- vector_store = SupabaseVectorStore(
10
- client=supabase,
11
- embedding=embeddings,
12
- table_name="documents",
13
- query_name="match_documents_langchain",
14
- )
 
 
 
 
 
 
 
 
15
 
16
  def retrieve(query: str) -> str:
17
- results = vector_store.similarity_search(query)
18
- if results:
19
- return results[0].page_content
20
- else:
21
- return "No similar questions found."
 
 
 
 
 
1
+ # retrievers/custom_retriever.py
2
+
3
  import os
4
  from langchain_huggingface import HuggingFaceEmbeddings
5
  from langchain_community.vectorstores import SupabaseVectorStore
6
  from supabase.client import create_client
7
  from config import settings
8
 
9
+ def get_vector_store():
10
+ # Read env variables only when needed
11
+ supabase_url = settings.supabase_url
12
+ supabase_key = settings.supabase_key
13
+
14
+ if not supabase_url or not supabase_key:
15
+ raise ValueError("SUPABASE_URL and SUPABASE_SERVICE_KEY must be set in your environment or .env file.")
16
+
17
+ embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-mpnet-base-v2")
18
+ supabase = create_client(supabase_url, supabase_key)
19
+ return SupabaseVectorStore(
20
+ client=supabase,
21
+ embedding=embeddings,
22
+ table_name="documents",
23
+ query_name="match_documents_langchain",
24
+ )
25
 
26
  def retrieve(query: str) -> str:
27
+ try:
28
+ vector_store = get_vector_store()
29
+ results = vector_store.similarity_search(query)
30
+ if results:
31
+ return results[0].page_content
32
+ except Exception as e:
33
+ return f"Retriever is not available (reason: {e})"
34
+ return "No similar questions found."
35
+