33
44namespace TypeAgent . ConversationMemory ;
55
6- public class Memory < TMessage > : Conversation < TMessage >
6+ public class Memory < TMessage > : Conversation < TMessage > , IMemory
77 where TMessage : class , IMessage , new ( )
88{
99
@@ -18,4 +18,69 @@ public Memory(MemorySettings settings, IStorageProvider<TMessage> storageProvide
1818 public string Name { get ; set ; }
1919
2020 public IList < string > Tags { get ; set ; }
21+
22+ public NoiseText NoiseTerms { get ; set ; }
23+
24+ private bool UseScoped => Settings . UseScopedSearch is not null && Settings . UseScopedSearch . Value ;
25+
26+ public async ValueTask < IList < ConversationSearchResult > > SearchAsync (
27+ string searchText ,
28+ LangSearchOptions ? options = null ,
29+ LangSearchFilter ? filter = null ,
30+ LangSearchDebugContext ? debugContext = null ,
31+ CancellationToken cancellationToken = default
32+ )
33+ {
34+ options = AdjustLanguageSearchOptions ( options ) ;
35+ if ( UseScoped )
36+ {
37+ // Using Structured Tags for scoping
38+ throw new NotImplementedException ( ) ;
39+ }
40+ else
41+ {
42+ IConversation conversation = this ;
43+ return await conversation . SearchAsync (
44+ searchText ,
45+ Settings . QueryTranslator ,
46+ options ,
47+ filter ,
48+ debugContext ,
49+ cancellationToken
50+ ) . ConfigureAwait ( false ) ;
51+ }
52+ }
53+
54+ public virtual IList < PromptSection > ? GetModelInstructions ( )
55+ {
56+ return null ;
57+ }
58+
59+ private LangSearchOptions AdjustLanguageSearchOptions ( LangSearchOptions ? options )
60+ {
61+ // Clone options so we can edit them
62+ options = options is null
63+ ? LangSearchOptions . CreateTypical ( )
64+ : new LangSearchOptions ( options ) ;
65+
66+ var instructions = GetModelInstructions ( ) ;
67+ if ( ! instructions . IsNullOrEmpty ( ) )
68+ {
69+ if ( ! options . ModelInstructions . IsNullOrEmpty ( ) )
70+ {
71+ options . ModelInstructions . AddRange ( instructions ) ;
72+ }
73+ else
74+ {
75+ options . ModelInstructions = instructions ;
76+ }
77+ }
78+ // Filter noise terms
79+ options . CompilerSettings . TermFilter = ( t ) =>
80+ {
81+ return NoiseTerms . IsNullOrEmpty ( ) || ! NoiseTerms . Contains ( t ) ;
82+ } ;
83+
84+ return options ;
85+ }
2186}
0 commit comments