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
20e4f6cc
Commit
20e4f6cc
authored
Jun 18, 2024
by
Timothy J. Baek
Browse files
refac
parent
eb217504
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
10 deletions
+10
-10
backend/apps/rag/utils.py
backend/apps/rag/utils.py
+10
-10
No files found.
backend/apps/rag/utils.py
View file @
20e4f6cc
...
@@ -237,7 +237,7 @@ def get_embedding_function(
...
@@ -237,7 +237,7 @@ def get_embedding_function(
def
get_rag_context
(
def
get_rag_context
(
doc
s
,
file
s
,
messages
,
messages
,
embedding_function
,
embedding_function
,
k
,
k
,
...
@@ -245,29 +245,29 @@ def get_rag_context(
...
@@ -245,29 +245,29 @@ def get_rag_context(
r
,
r
,
hybrid_search
,
hybrid_search
,
):
):
log
.
debug
(
f
"
docs:
{
doc
s
}
{
messages
}
{
embedding_function
}
{
reranking_function
}
"
)
log
.
debug
(
f
"
files:
{
file
s
}
{
messages
}
{
embedding_function
}
{
reranking_function
}
"
)
query
=
get_last_user_message
(
messages
)
query
=
get_last_user_message
(
messages
)
extracted_collections
=
[]
extracted_collections
=
[]
relevant_contexts
=
[]
relevant_contexts
=
[]
for
doc
in
doc
s
:
for
file
in
file
s
:
context
=
None
context
=
None
collection_names
=
(
collection_names
=
(
doc
[
"collection_names"
]
file
[
"collection_names"
]
if
doc
[
"type"
]
==
"collection"
if
file
[
"type"
]
==
"collection"
else
[
doc
[
"collection_name"
]]
else
[
file
[
"collection_name"
]]
)
)
collection_names
=
set
(
collection_names
).
difference
(
extracted_collections
)
collection_names
=
set
(
collection_names
).
difference
(
extracted_collections
)
if
not
collection_names
:
if
not
collection_names
:
log
.
debug
(
f
"skipping
{
doc
}
as it has already been extracted"
)
log
.
debug
(
f
"skipping
{
file
}
as it has already been extracted"
)
continue
continue
try
:
try
:
if
doc
[
"type"
]
==
"text"
:
if
file
[
"type"
]
==
"text"
:
context
=
doc
[
"content"
]
context
=
file
[
"content"
]
else
:
else
:
if
hybrid_search
:
if
hybrid_search
:
context
=
query_collection_with_hybrid_search
(
context
=
query_collection_with_hybrid_search
(
...
@@ -290,7 +290,7 @@ def get_rag_context(
...
@@ -290,7 +290,7 @@ def get_rag_context(
context
=
None
context
=
None
if
context
:
if
context
:
relevant_contexts
.
append
({
**
context
,
"source"
:
doc
})
relevant_contexts
.
append
({
**
context
,
"source"
:
file
})
extracted_collections
.
extend
(
collection_names
)
extracted_collections
.
extend
(
collection_names
)
...
...
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