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
6782e95c
Commit
6782e95c
authored
Mar 04, 2024
by
Firat Birlik
Browse files
recreate rag collection is now optional and only used for web requests
parent
5d4ff852
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
5 deletions
+7
-5
backend/apps/rag/main.py
backend/apps/rag/main.py
+7
-5
No files found.
backend/apps/rag/main.py
View file @
6782e95c
...
@@ -108,7 +108,7 @@ class StoreWebForm(CollectionNameForm):
...
@@ -108,7 +108,7 @@ class StoreWebForm(CollectionNameForm):
url
:
str
url
:
str
def
store_data_in_vector_db
(
data
,
collection_name
)
->
bool
:
def
store_data_in_vector_db
(
data
,
collection_name
,
overwrite
:
bool
=
False
)
->
bool
:
text_splitter
=
RecursiveCharacterTextSplitter
(
text_splitter
=
RecursiveCharacterTextSplitter
(
chunk_size
=
app
.
state
.
CHUNK_SIZE
,
chunk_overlap
=
app
.
state
.
CHUNK_OVERLAP
chunk_size
=
app
.
state
.
CHUNK_SIZE
,
chunk_overlap
=
app
.
state
.
CHUNK_OVERLAP
)
)
...
@@ -118,9 +118,11 @@ def store_data_in_vector_db(data, collection_name) -> bool:
...
@@ -118,9 +118,11 @@ def store_data_in_vector_db(data, collection_name) -> bool:
metadatas
=
[
doc
.
metadata
for
doc
in
docs
]
metadatas
=
[
doc
.
metadata
for
doc
in
docs
]
try
:
try
:
for
collection
in
CHROMA_CLIENT
.
list_collections
():
if
overwrite
:
if
collection_name
==
collection
.
name
:
for
collection
in
CHROMA_CLIENT
.
list_collections
():
CHROMA_CLIENT
.
delete_collection
(
name
=
collection_name
)
if
collection_name
==
collection
.
name
:
print
(
f
"deleting existing collection
{
collection_name
}
"
)
CHROMA_CLIENT
.
delete_collection
(
name
=
collection_name
)
collection
=
CHROMA_CLIENT
.
create_collection
(
collection
=
CHROMA_CLIENT
.
create_collection
(
name
=
collection_name
,
name
=
collection_name
,
...
@@ -359,7 +361,7 @@ def store_web(form_data: StoreWebForm, user=Depends(get_current_user)):
...
@@ -359,7 +361,7 @@ def store_web(form_data: StoreWebForm, user=Depends(get_current_user)):
if
collection_name
==
""
:
if
collection_name
==
""
:
collection_name
=
calculate_sha256_string
(
form_data
.
url
)[:
63
]
collection_name
=
calculate_sha256_string
(
form_data
.
url
)[:
63
]
store_data_in_vector_db
(
data
,
collection_name
)
store_data_in_vector_db
(
data
,
collection_name
,
overwrite
=
True
)
return
{
return
{
"status"
:
True
,
"status"
:
True
,
"collection_name"
:
collection_name
,
"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