Skip to content

Commit c5bd1a5

Browse files
committed
Configure RAG indexing through flags for media files
The RAG is able to index text but also media files, i.e. images, videos and audio, which is nice, but it can be a costful treatment. Therefore, we prefer to make it configurable through flags.
1 parent 88157d7 commit c5bd1a5

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

model/rag/index.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/url"
1212
"strings"
1313

14+
"github.com/cozy/cozy-stack/model/feature"
1415
"github.com/cozy/cozy-stack/model/instance"
1516
"github.com/cozy/cozy-stack/model/job"
1617
"github.com/cozy/cozy-stack/model/note"
@@ -74,6 +75,30 @@ func callRAGIndexer(inst *instance.Instance, doctype string, change couchdb.Chan
7475
if strings.HasPrefix(change.DocID, "_design/") {
7576
return nil
7677
}
78+
flags, err := feature.GetFlags(inst)
79+
class, _ := change.Doc.Get("class").(string)
80+
81+
if class == consts.ImageClass {
82+
// Index images only if flag allows it
83+
allowImage, ok := flags.M["rag.index.image.enabled"].(bool)
84+
if !ok || !allowImage {
85+
return nil
86+
}
87+
}
88+
if class == consts.VideoClass {
89+
// Index videos only if flag allows it
90+
allowVideo, ok := flags.M["rag.index.video.enabled"].(bool)
91+
if !ok || !allowVideo {
92+
return nil
93+
}
94+
}
95+
if class == consts.AudioClass {
96+
// Index audio only if flag allows it
97+
allowAudio, ok := flags.M["rag.index.audio.enabled"].(bool)
98+
if !ok || !allowAudio {
99+
return nil
100+
}
101+
}
77102
if change.Doc.Get("type") == consts.DirType {
78103
return nil
79104
}
@@ -158,6 +183,7 @@ func callRAGIndexer(inst *instance.Instance, doctype string, change couchdb.Chan
158183
}
159184
internalID, _ := change.Doc.Get("internal_vfs_id").(string)
160185
var content io.Reader
186+
161187
if mime == consts.NoteMimeType {
162188
metadata, _ := change.Doc.Get("metadata").(map[string]interface{})
163189
schema, _ := metadata["schema"].(map[string]interface{})

pkg/consts/file.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ const (
3434
DocsExtension = ".docs-note"
3535
// MarkdownExtension is the extension for the markdown files.
3636
MarkdownExtension = ".md"
37+
// ImageClass is the class for the image files
38+
ImageClass = "image"
39+
// VideoClass is the class for the video files
40+
VideoClass = "video"
41+
// AudioClass is the class for the audio files
42+
AudioClass = "audio"
3743
)
3844

3945
const (

0 commit comments

Comments
 (0)