1
1
import json
2
+ from typing import Any , Optional
2
3
from langchain_openai import OpenAIEmbeddings
3
- from langchain_community . vectorstores import SupabaseVectorStore
4
+ from rag . supabase_vectorstore import SupabaseVectorStore
4
5
from db .supabase .client import get_client
5
6
from data_class import GitDocConfig , GitIssueConfig , S3Config
6
7
from rag .github_file_loader import GithubFileLoader
@@ -23,15 +24,15 @@ def convert_document_to_dict(document):
23
24
24
25
def init_retriever ():
25
26
embeddings = OpenAIEmbeddings ()
26
- db = SupabaseVectorStore (
27
+ vector_store = SupabaseVectorStore (
27
28
embedding = embeddings ,
28
29
client = get_client (),
29
30
table_name = TABLE_NAME ,
30
31
query_name = QUERY_NAME ,
31
32
chunk_size = CHUNK_SIZE ,
32
33
)
33
34
34
- return db .as_retriever ()
35
+ return vector_store .as_retriever ()
35
36
36
37
37
38
def init_s3_Loader (config : S3Config ):
@@ -61,38 +62,43 @@ def init_github_file_loader(config: GitDocConfig):
61
62
)
62
63
return loader
63
64
64
- def supabase_embedding (documents ):
65
+ def supabase_embedding (documents , ** kwargs : Any ):
65
66
from langchain_text_splitters import CharacterTextSplitter
66
67
67
68
try :
68
69
text_splitter = CharacterTextSplitter (chunk_size = CHUNK_SIZE , chunk_overlap = CHUNK_OVERLAP )
69
70
docs = text_splitter .split_documents (documents )
70
71
embeddings = OpenAIEmbeddings ()
71
- SupabaseVectorStore .from_documents (
72
+ vector_store = SupabaseVectorStore .from_documents (
72
73
docs ,
73
74
embeddings ,
74
75
client = get_client (),
75
76
table_name = TABLE_NAME ,
76
77
query_name = QUERY_NAME ,
77
78
chunk_size = CHUNK_SIZE ,
79
+ ** kwargs
78
80
)
79
- return json .dumps ({
80
- "success" : True ,
81
- "message" : "Knowledge added successfully!" ,
82
- "docs_len" : len (documents )
83
- })
81
+ return vector_store
84
82
except Exception as e :
85
- return json .dumps ({
86
- "success" : False ,
87
- "message" : str (e )
88
- })
83
+ print (e )
84
+ return None
89
85
90
86
91
- def add_knowledge_by_issues (config : GitIssueConfig ):
87
+ def add_knowledge_by_issues (config : GitIssueConfig , ):
92
88
try :
93
89
loader = init_github_issue_loader (config )
94
90
documents = loader .load ()
95
- supabase_embedding (documents )
91
+ store = supabase_embedding (documents , repo_name = config .repo_name )
92
+ if (store ):
93
+ return json .dumps ({
94
+ "success" : True ,
95
+ "message" : "Knowledge added successfully!" ,
96
+ })
97
+ else :
98
+ return json .dumps ({
99
+ "success" : False ,
100
+ "message" : "Knowledge not added!"
101
+ })
96
102
except Exception as e :
97
103
return json .dumps ({
98
104
"success" : False ,
@@ -103,7 +109,18 @@ def add_knowledge_by_doc(config: GitDocConfig):
103
109
try :
104
110
loader = init_github_file_loader (config )
105
111
documents = loader .load ()
106
- supabase_embedding (documents )
112
+ store = supabase_embedding (documents , repo_name = config .repo_name , commit_id = config .commit_id , commit_sha = config .commit_sha )
113
+ if (store ):
114
+ return json .dumps ({
115
+ "success" : True ,
116
+ "message" : "Knowledge added successfully!" ,
117
+ })
118
+ else :
119
+ return json .dumps ({
120
+ "success" : False ,
121
+ "message" : "Knowledge not added!"
122
+ })
123
+
107
124
except Exception as e :
108
125
return json .dumps ({
109
126
"success" : False ,
0 commit comments