4using System.IO.Compression;
5using System.Threading.Tasks;
41 [Tooltip(
"Search method type to use for RAG. SimpleSearch is a simple brute-force search, while DBSearch is a fast Approximate Nearest Neighbor (ANN) method (recommended!).")]
44 [Tooltip(
"Search method GameObject.")]
47 [Tooltip(
"Chunking method type to use for RAG for splitting the inputs into chunks. This is useful to have a more consistent meaning within each data part.")]
50 [Tooltip(
"Chunking method GameObject.")]
77 protected void ConstructSearch()
79 search = ConstructComponent<SearchMethod>(Type.GetType(
"LLMUnity." +
searchType.ToString()), (previous, current) => current.llmEmbedder.llm = previous.llmEmbedder.llm);
83 protected void ConstructChunking()
87 chunking = ConstructComponent<Chunking>(type);
91 public override void UpdateGameObjects()
93 if (
this ==
null)
return;
98 protected Searchable GetSearcher()
102 throw new Exception(
"The search GameObject is null");
106 private void OnValidateUpdate()
108 EditorApplication.delayCall -= OnValidateUpdate;
112 public virtual void OnValidate()
114 if (!Application.isPlaying) EditorApplication.delayCall += OnValidateUpdate;
119 public override string Get(
int key) {
return GetSearcher().Get(key); }
120 public override async Task<int>
Add(
string inputString,
string group =
"") {
return await GetSearcher().Add(inputString, group); }
121 public override int Remove(
string inputString,
string group =
"") {
return GetSearcher().Remove(inputString, group); }
122 public override void Remove(
int key) { GetSearcher().Remove(key); }
123 public override int Count() {
return GetSearcher().Count(); }
124 public override int Count(
string group) {
return GetSearcher().Count(group); }
125 public override void Clear() { GetSearcher().Clear(); }
126 public override async Task<int>
IncrementalSearch(
string queryString,
string group =
"") {
return await GetSearcher().IncrementalSearch(queryString, group);}
127 public override (
string[],
float[], bool)
IncrementalFetch(
int fetchKey,
int k) {
return GetSearcher().IncrementalFetch(fetchKey, k);}
128 public override (
int[],
float[], bool)
IncrementalFetchKeys(
int fetchKey,
int k) {
return GetSearcher().IncrementalFetchKeys(fetchKey, k);}
130 public override void Save(ZipArchive archive) { GetSearcher().Save(archive); }
131 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...
SearchMethod search
Search method GameObject.
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 ...
SearchMethods searchType
Search method type to use for RAG. SimpleSearch is a simple brute-force search, while DBSearch is a f...
ChunkingMethods chunkingType
Chunking method type to use for RAG for splitting the inputs into chunks. This is useful to have a mo...
Chunking chunking
Chunking method GameObject.
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.