Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
ff8a55a8
Commit
ff8a55a8
authored
Mar 24, 2024
by
Timothy J. Baek
Browse files
refac: rag api
parent
7e0ea8f7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
3 deletions
+7
-3
backend/apps/rag/main.py
backend/apps/rag/main.py
+7
-3
No files found.
backend/apps/rag/main.py
View file @
ff8a55a8
...
@@ -303,14 +303,14 @@ def store_data_in_vector_db(data, collection_name, overwrite: bool = False) -> b
...
@@ -303,14 +303,14 @@ def store_data_in_vector_db(data, collection_name, overwrite: bool = False) -> b
def
store_text_in_vector_db
(
def
store_text_in_vector_db
(
text
,
na
me
,
collection_name
,
overwrite
:
bool
=
False
text
,
me
tadata
,
collection_name
,
overwrite
:
bool
=
False
)
->
bool
:
)
->
bool
:
text_splitter
=
RecursiveCharacterTextSplitter
(
text_splitter
=
RecursiveCharacterTextSplitter
(
chunk_size
=
app
.
state
.
CHUNK_SIZE
,
chunk_size
=
app
.
state
.
CHUNK_SIZE
,
chunk_overlap
=
app
.
state
.
CHUNK_OVERLAP
,
chunk_overlap
=
app
.
state
.
CHUNK_OVERLAP
,
add_start_index
=
True
,
add_start_index
=
True
,
)
)
docs
=
text_splitter
.
create_documents
([
text
],
metadatas
=
[
{
"name"
:
name
}
])
docs
=
text_splitter
.
create_documents
([
text
],
metadatas
=
[
metadata
])
return
store_docs_in_vector_db
(
docs
,
collection_name
,
overwrite
)
return
store_docs_in_vector_db
(
docs
,
collection_name
,
overwrite
)
...
@@ -493,7 +493,11 @@ def store_text(
...
@@ -493,7 +493,11 @@ def store_text(
if
collection_name
==
None
:
if
collection_name
==
None
:
collection_name
=
calculate_sha256_string
(
form_data
.
content
)
collection_name
=
calculate_sha256_string
(
form_data
.
content
)
result
=
store_text_in_vector_db
(
form_data
.
content
,
form_data
.
name
,
collection_name
)
result
=
store_text_in_vector_db
(
form_data
.
content
,
metadata
=
{
"name"
:
form_data
.
name
,
"created_by"
:
user
.
id
},
collection_name
=
collection_name
,
)
if
result
:
if
result
:
return
{
"status"
:
True
,
"collection_name"
:
collection_name
}
return
{
"status"
:
True
,
"collection_name"
:
collection_name
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment