4using System.IO.Compression;
5using System.Threading.Tasks;
53 searchType = searchMethod;
54 chunkingType = chunkingMethod;
65 if (chunking !=
null) chunking.
ReturnChunks(returnChunks);
69 protected void ConstructSearch()
71 search = ConstructComponent<SearchMethod>(Type.GetType(
"LLMUnity." + searchType.ToString()), (previous, current) => current.llmEmbedder.llm = previous.llmEmbedder.llm);
72 if (chunking !=
null) chunking.
SetSearch(search);
75 protected void ConstructChunking()
78 if (chunkingType !=
ChunkingMethods.NoChunking) type = Type.GetType(
"LLMUnity." + chunkingType.ToString());
79 chunking = ConstructComponent<Chunking>(type);
80 if (chunking !=
null) chunking.
SetSearch(search);
83 public override void UpdateGameObjects()
85 if (
this ==
null)
return;
90 protected Searchable GetSearcher()
92 if (chunking !=
null)
return chunking;
93 if (search !=
null)
return search;
94 throw new Exception(
"The search GameObject is null");
98 private void OnValidateUpdate()
100 EditorApplication.delayCall -= OnValidateUpdate;
104 public virtual void OnValidate()
106 if (!Application.isPlaying) EditorApplication.delayCall += OnValidateUpdate;
111 public override string Get(
int key) {
return GetSearcher().Get(key); }
112 public override async Task<int>
Add(
string inputString,
string group =
"") {
return await GetSearcher().Add(inputString, group); }
113 public override int Remove(
string inputString,
string group =
"") {
return GetSearcher().Remove(inputString, group); }
114 public override void Remove(
int key) { GetSearcher().Remove(key); }
115 public override int Count() {
return GetSearcher().Count(); }
116 public override int Count(
string group) {
return GetSearcher().Count(group); }
117 public override void Clear() { GetSearcher().Clear(); }
118 public override async Task<int>
IncrementalSearch(
string queryString,
string group =
"") {
return await GetSearcher().IncrementalSearch(queryString, group);}
119 public override (
string[],
float[], bool)
IncrementalFetch(
int fetchKey,
int k) {
return GetSearcher().IncrementalFetch(fetchKey, k);}
120 public override (
int[],
float[], bool)
IncrementalFetchKeys(
int fetchKey,
int k) {
return GetSearcher().IncrementalFetchKeys(fetchKey, k);}
122 public override void Save(ZipArchive archive) { GetSearcher().Save(archive); }
123 public override void Load(ZipArchive archive) { GetSearcher().Load(archive); }
Class implementing the chunking functionality.
void ReturnChunks(bool returnChunks)
Set to true to return chunks or the direct input with the Search function.
Class implementing a search with a vector database. The search results are retrieved with Approximate...
Class implementing the LLM server.
Class implementing a Retrieval Augmented Generation (RAG) system based on a search method and an opti...
void Init(SearchMethods searchMethod=SearchMethods.SimpleSearch, ChunkingMethods chunkingMethod=ChunkingMethods.NoChunking, LLM llm=null)
Constructs the Retrieval Augmented Generation (RAG) system based on the provided search and chunking ...
void ReturnChunks(bool returnChunks)
Set to true to return chunks or the direct input with the Search function.
Class implementing the search method template.
void SetLLM(LLM llm)
Sets the LLM for encoding the search entries.
void SetSearch(SearchMethod search)
Sets the search method of the plugin.
Class implementing the search template.
int Remove(string inputString, string group="")
Removes a phrase from the search.
Task< int > Add(string inputString, string group="")
Adds a phrase to the search.
int Count()
Returns a count of the phrases.
void Clear()
Clears the search object.
ValueTuple< int[], float[], bool > IncrementalFetchKeys(int fetchKey, int k)
Retrieves the most similar search results in batches (incremental search). The phrase keys and distan...
virtual ValueTuple< string[], float[], bool > IncrementalFetch(int fetchKey, int k)
Retrieves the most similar search results in batches (incremental search). The most similar results a...
void IncrementalSearchComplete(int fetchKey)
Completes the search and clears the cached results for an incremental search.
string Get(int key)
Retrieves the phrase with the specific id.
void Save(string filePath)
Saves the state of the search object.
async Task< bool > Load(string filePath)
Loads the state of the search object.
Task< int > IncrementalSearch(string queryString, string group="")
Allows to do search and retrieve results in batches (incremental search).
Class implementing a sentence-based splitter.
Class implementing a simple search that compares the enconding of the search query with all the searc...
Class implementing a token-based splitter.
Class implementing a word-based splitter.
SearchMethods
Search methods implemented in LLMUnity.
ChunkingMethods
Chunking methods implemented in LLMUnity.