How does the databank / RAG / vector storage work?
My understanding is that using a world info, I can implement RAG into my chat.
And that I can store multiple 'memories' or other info in one world info entry, and the chunking will only return a relevant chunk.
But what I get is the entire entry.
Settings are 1KB size threshold, 512 char chunk size.
Assistant
User
So it does or doesn't split world info entries to the most relevant parts?
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
The databank / RAG (Retrieval-Augmented Generation) / vector storage in SillyTavern is an advanced system designed to enable the use of vector embeddings for retrieving relevant information from stored "memories" or other data during chat sessions. Here's how it works, based on the provided context:
Core Components
World Info as a Databank:
World Info entries act as a database for storing knowledge snippets, "memories," or structured information.
Each World Info entry can contain multiple pieces of information (e.g., descriptions, lore, facts, etc.).
These entries are treated as documents for later retrieval using vector search.
Chunking ensures only relevant pieces of information are retrieved instead of entire entries.
Vector Storage:
The vector storage system converts text into numerical embeddings using configured sources like OpenAI, Cohere, Transformers, or other embedding models.
These embeddings are stored in a local index using the vectra library.
When a query is made during a chat, the system retrieves the most relevant chunks of information based on similarity to the user's input.
Chunking:
Large entries in World Info are split into smaller chunks for efficient vector embedding and retrieval.
This ensures that only the most relevant chunk of information is retrieved during a query, rather than the entire entry.
The chunk size is configurable (e.g., 512 characters in your case).
How It Works
Storing World Info in Vector Storage:
When World Info is processed, large entries are automatically split into chunks based on the configured 512 char chunk size (or other size).
Each chunk is embedded (converted into a vector) and stored in a vector database (e.g., using vectra.LocalIndex).
Metadata, such as the entry's hash, world name, or other identifiers, is also stored alongside the embeddings for traceability.
Vector Embedding Sources:
SillyTavern supports various vector embedding sources, including:
OpenAI: Uses models like text-embedding-ada-002.
Cohere: Embedding API with search query/document modes.
Transformers: Generates embeddings using a local pipeline.
MakerSuite: Google's API for embeddings.
Others: NomicAI, LlamaCPP, Ollama, VLLM, etc.
The embeddings are generated by these sources and stored locally.
Querying (RAG):
During a chat, the system performs a vector search to retrieve relevant information.
A query (e.g., the user's message or conversation context) is embedded into a vector.
The system compares this query vector against the stored vectors in the database to find the most relevant chunks.
Only chunks that pass a similarity threshold (e.g., cosine similarity) are returned.
Chunk Retrieval:
Even if an entry contains multiple "memories" or data points, only the relevant chunk(s) are returned and injected into the chat.
This prevents unnecessary information from being included and keeps responses concise.
Size Thresholds:
The 1KB size threshold ensures that the total amount of returned data does not exceed a manageable size.
The 512 char chunk size ensures that each chunk processed and stored in the vector database is small and granular.
Relevant Code Insights
Chunking and Vector Storage
The insertVectorItems function in vectors.js handles chunking and storage:
Store structured data in a World Info entry (e.g., character backstory, lore, or Q&A pairs).
Ensure large entries are chunked automatically during vector storage.
Retrieval During Chat:
When chatting, the system takes the user's message (or the chat context), converts it into a query vector, and searches the stored vectors.
The most relevant chunks are retrieved and injected into the conversation as context for the AI.
Example Settings:
Chunk size: 512 characters
Size threshold: 1KB
TopK: 10 (retrieve up to 10 most relevant chunks)
Threshold: 0.5 (minimum similarity score for relevance)
Troubleshooting: Why Entire Entries Are Returned
If you're currently retrieving the entire entry instead of individual chunks, here are potential reasons:
Improper Chunking:
Ensure the chunking mechanism is working correctly. Entries must be split into smaller chunks during insertion into the vector database.
Query Threshold:
If the similarity threshold is too low, the system might return the entire entry instead of filtering chunks.
Missing Chunk Metadata:
Ensure each chunk is stored with proper metadata (e.g., hash, index) to allow retrieval of specific chunks.
Debugging:
Add logs to verify that the chunking and vector retrieval process is operating as expected.
Summary
SillyTavern's RAG system uses World Info as a databank.
Large entries are chunked into smaller pieces, embedded as vectors, and stored in a vector database.
During a chat, only the most relevant chunks are retrieved based on vector similarity.
The settings (chunk size, size threshold, similarity threshold) and the embedding source affect performance and retrieval quality.
By tweaking the settings and ensuring proper chunking, you can fully implement RAG to retrieve relevant information efficiently.
Yes, SillyTavern does split World Info entries into smaller chunks to enable retrieval of only the most relevant parts during a query. However, whether this process is working correctly in your setup depends on several factors, which I will explain below.
How World Info Splitting Works
Chunking Process:
When you add a World Info entry, large entries are automatically split into smaller chunks during vector storage.
For example, if your entry is 1500 characters long and the configured chunk size is 512 characters, the system will divide the entry into 3 chunks:
Chunk 1: 512 characters
Chunk 2: 512 characters
Chunk 3: Remaining 476 characters
Storing Chunks:
Each chunk is stored as a separate "document" in the vector database.
The system associates metadata with each chunk, such as which World Info entry it came from, its position within the entry, and its hashed identifier.
Retrieval of Relevant Chunks:
During a chat, when the system performs a vector query, it compares the query vector to the stored chunks.
Only the most relevant chunk(s) (based on similarity scores) are retrieved and injected into the chat context.
This prevents the entire World Info entry from being returned unless the entire entry is highly relevant.
When It Doesn't Work
If you're seeing the entire World Info entry being returned instead of the most relevant chunk, this could indicate an issue in the setup or configuration. Here's what might be happening:
Chunking Not Happening:
If the World Info entry wasn't properly split into chunks during insertion, the entire entry would be treated as a single chunk. This would result in the entire entry being retrieved instead of just the relevant part.
Check whether the chunking logic is respecting the 512 char chunk size setting.
Low Query Specificity:
If the query (the user's message) is too broad or doesn't match any specific chunk well, the system might retrieve the entire entry because it can't narrow down the results.
Threshold Misconfiguration:
If the similarity threshold (e.g., 0.5) is too low, the system might retrieve all chunks of an entry, effectively returning the full entry.
Example: If all parts of the entry are somewhat relevant, they may all be included in the response.
Improper Vector Storage Setup:
If the vector storage wasn't set up correctly, all chunks of an entry might be embedded and retrieved as a single unit instead of as separate chunks.
Metadata Mismanagement:
If the chunk metadata wasn't stored properly, the system might not be able to identify and retrieve chunks individually.
How to Verify Chunking
To confirm whether the World Info entries are being split into chunks:
Inspect the Vector Database:
Each chunk of a World Info entry should be stored as a separate document with its own vector representation.
The metadata should include information about the chunk, such as its position or hash.
Test a Query:
Perform a query using a specific part of the World Info entry.
Only the chunk containing that specific part should be returned.
Check Logs:
Add logging to the insertVectorItems function or the vector query logic to see how entries are chunked and stored.
Key Code for Chunking
The chunking logic happens implicitly during the vector insertion in the insertVectorItems function. Here's a breakdown:
Chunk Preparation:
Each World Info entry is split into smaller chunks (items.map(x => x.text)), and these chunks are embedded and stored in the vector database:
This determines how large each chunk of a World Info entry will be.
Size Threshold:
Configured as 1KB (1024 bytes).
This limits the total size of retrieved data to ensure only the most relevant information is included.
Top-K Results:
Limits the number of chunks returned during a query (e.g., topK = 10 means the top 10 most relevant chunks are returned).
Similarity Threshold:
Controls how "relevant" a chunk must be to be included in the results.
Example: If the threshold is 0.5, chunks with similarity scores below 0.5 will be excluded.
How to Fix the Issue
If the system is returning entire entries instead of chunks, try these steps:
Verify Chunking:
Ensure that the World Info entries are being split into chunks during insertion.
Add debug logs to insertVectorItems to confirm this.
Adjust Thresholds:
Increase the similarity threshold to ensure only the most relevant chunks are retrieved.
Example: Set the threshold to 0.7 or higher to exclude loosely relevant chunks.
Test with Smaller Entries:
Use smaller World Info entries to test whether chunking and retrieval are working as expected.
Inspect Metadata:
Check the metadata stored with each chunk to ensure it includes the necessary identifiers for retrieval.
Debug Retrieval Logic:
Add logs to the queryCollection function to see which chunks are being retrieved and why.
Summary
Does SillyTavern split World Info entries into chunks?
Yes, it splits entries into smaller chunks based on the configured chunk size (e.g., 512 characters).
Why might the entire entry be returned instead of chunks?
Chunking may not be happening correctly, or the retrieval logic might return too many chunks due to low thresholds or improper query specificity.
How to fix this?
Verify the chunking process, adjust thresholds, and test with different queries to ensure that only the most relevant chunks are retrieved.
By ensuring proper chunking and configuring thresholds, you can make SillyTavern's RAG system retrieve only the most relevant parts of World Info entries.