This commit is contained in:
@@ -1020,6 +1020,32 @@ func (s *Store) persistVectorCache() error {
|
||||
return s.persistSnapshot()
|
||||
}
|
||||
|
||||
// FindMetadata searches knowledge metadata without copying the complete corpus.
|
||||
// It is intended for interactive UI lookups on very large knowledge stores.
|
||||
func (s *Store) FindMetadata(query string, limit int) []model.KnowledgeDoc {
|
||||
if s == nil {
|
||||
return nil
|
||||
}
|
||||
q := strings.ToLower(strings.TrimSpace(query))
|
||||
if limit <= 0 {
|
||||
limit = 30
|
||||
}
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
out := make([]model.KnowledgeDoc, 0, limit)
|
||||
for _, d := range s.docs {
|
||||
hay := strings.ToLower(d.ID + " " + d.Title + " " + strings.Join(d.Keywords, " ") + " " + strings.Join(d.ExternalCategories, " "))
|
||||
if q != "" && !strings.Contains(hay, q) {
|
||||
continue
|
||||
}
|
||||
out = append(out, d)
|
||||
if len(out) >= limit {
|
||||
break
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *Store) ManagedDir() string {
|
||||
if s == nil {
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user