RAG Vector Search Settings
The RAG module of Skybuffer AI, the application py_rag_m of the archive skybfryai_rag_m, stores the vectors (embeddings) of the documents in the Document Grounding Hub, and searches them when an AI agent grounds its answer. The settings on this page control how it stores the vectors and how the vector search runs. The page is for the administrators who deploy Skybuffer AI on SAP BTP or on SAP HANA XS advanced.
A new installation needs no change: the defaults suit most installations. An installation with documents uploaded before the compact storage switches them once, as Switch an existing installation to the compact storage describes.
The settings at a glance
Section titled “The settings at a glance”| Setting | Values | Default | What it controls |
|---|---|---|---|
PY_RAG_M_EMB_STORAGE |
PIVOT, ROWS |
PIVOT |
How the vectors are stored: in the compact format, or one row per value |
PY_RAG_M_VECTOR_SEARCH |
MASK, EXACT |
MASK |
Whether a large search first selects candidates by bit masks |
PY_RAG_M_MASK_CANDIDATES |
a whole number of 1 or more | 50000 |
How many candidates get the exact cosine similarity with MASK |
PY_RAG_M_MIN_SIMILARITY |
0 to 1 | 0.45 |
The similarity threshold when a search request sends none |
PY_RAG_M_EMB_NORMALIZE |
TRUE, FALSE |
TRUE |
Whether the vectors are scaled to length 1 before they are stored |
PY_RAG_M_SEARCH_BLOCK_SIZE |
a whole number of 1 or more | 50000 |
How many chunks the vector search compares with the query in one step |
Set or change a value
Section titled “Set or change a value”The deployment of skybfryai_rag_m sets these values, with the defaults above. To change a value, set it on the application py_rag_m and restart it:
# SAP HANA XS advancedxs set-env py_rag_m PY_RAG_M_VECTOR_SEARCH EXACTxs restart py_rag_m# SAP BTP, Cloud Foundry environmentcf set-env py_rag_m PY_RAG_M_VECTOR_SEARCH EXACTcf restart py_rag_mThe commands use the application name py_rag_m; if your installation uses another name, use that one. The next deployment of skybfryai_rag_m sets the values of its archive again: set your own values again after each deployment.
- Restart when no document is being uploaded: the uploads run inside
py_rag_m, and a restart stops them. - A value that is not allowed falls back to the default, and
py_rag_mlogs an error. For example,PY_RAG_M_VECTOR_SEARCH=EXECruns asMASK. A missing setting takes the default, with a warning in the log. - With
PY_RAG_M_LOG_LEVEL=INFO, the log shows the values in use at start, for examplesettings: VECTOR_SEARCH = MASK.
The settings
Section titled “The settings”PY_RAG_M_EMB_STORAGE
Section titled “PY_RAG_M_EMB_STORAGE”- PIVOT (default): the compact storage. A vector is stored as rows of 128 two-byte values, 8 rows for a vector of 1,024 values, and its length and scale are stored once. It needs about a ninth of the space of
ROWS, and it is the only storage that supportsMASK. The two-byte values change the similarity by at most 0.000016: the search returns the same chunks. - ROWS: one row per value, 1,024 rows for a chunk with a vector of 1,024 values. It is kept as the fallback.
- A document is stored in the format in force when it is uploaded, and the vector search reads only the format in force when it runs. Deleting a document or a chunk removes its vectors in both formats.
- Switching from
ROWStoPIVOTneeds the switch of the documents stored before. Switching back toROWShides from the search every document uploaded withPIVOT, until it is uploaded again. - At start,
py_rag_mlogs an error with the number of chunks its search cannot find: withPIVOT, the chunks not yet switched to the compact storage; withROWS, the chunks stored only in the compact storage.
PY_RAG_M_VECTOR_SEARCH
Section titled “PY_RAG_M_VECTOR_SEARCH”- MASK (default): when a search covers more chunks than
PY_RAG_M_MASK_CANDIDATES, it first compares the bit masks of the chunks with the mask of the query, one bit per value (positive or not), and only the closest chunks get the exact cosine similarity. A search over fewer chunks stays exact. - EXACT: the exact cosine similarity of every chunk searched. It is also the quick way back if the results of
MASKare in doubt: no data changes, only a restart. MASKneedsPY_RAG_M_EMB_STORAGE=PIVOT. WithROWS, the search is exact, and a warning is logged.- Only searches over more than 50,000 chunks change. On a document of 233,000 chunks, a search took 5.4 s instead of 8.9 s, and less than half the CPU time of SAP HANA. The results are approximate: see
PY_RAG_M_MASK_CANDIDATESand Measured effect. - Every chunk needs its mask. Uploads write it; for the chunks stored before, the switch writes it. Chunks without a mask always become candidates: if a search covers more of them than
PY_RAG_M_MASK_CANDIDATES, some chunks are not compared at all.
PY_RAG_M_MASK_CANDIDATES
Section titled “PY_RAG_M_MASK_CANDIDATES”- The number of candidates that get the exact cosine similarity with
MASK, and the number of chunks above which the masks are used at all. - A larger number is closer to the exact search, and slower. A smaller one is faster, and more of the top chunks differ from those of the exact search.
- Tested on a document of 233,000 chunks: with 50,000, all 31 test queries kept the top 10 chunks of the exact search. With 20,000, the search was about a third faster, but 8 of the 310 top chunks changed.
- A value below 1, or one that is not a number, falls back to 50,000.
PY_RAG_M_MIN_SIMILARITY
Section titled “PY_RAG_M_MIN_SIMILARITY”- The lowest similarity, from 0 to 1, that a chunk needs to be returned. It is used when a search request sends no threshold of its own,
min_similarityormax_distance. 0 means no threshold. - Values outside 0 to 1 are clamped to that range; a value that is not a number falls back to 0.45.
- In a test of 100 queries to two documents, 0.45 found the answer for 82 of the 86 queries that have one, and the 14 queries without an answer in the documents returned 21 chunks. With 0.5: 80 answers and 16 such chunks. Without a threshold: 83 answers and 140 such chunks.
PY_RAG_M_EMB_NORMALIZE
Section titled “PY_RAG_M_EMB_NORMALIZE”- TRUE (default):
py_rag_mscales every vector, of documents and of queries, to length 1 before it stores or searches it. FALSE: the vectors are stored as the model returns them. - Both values give the same similarity, because the search uses the length of every vector. A change applies to the documents uploaded after it. Keep
TRUE. - Unlike the other settings, any value other than
TRUEcounts asFALSE, without an error in the log.
PY_RAG_M_SEARCH_BLOCK_SIZE
Section titled “PY_RAG_M_SEARCH_BLOCK_SIZE”- How many chunks the vector search compares with the query in one step. The default is 50,000; earlier releases used 1,000.
- Larger blocks mean fewer steps and a faster search, but more SAP HANA memory in each step. With 50,000, a document of 233,000 chunks is searched exactly in about 8 s with 650 MB (
PIVOT), or in 10 s with 260 MB (ROWS). Keep 50,000 unless SAP HANA memory is short.
Switch an existing installation to the compact storage
Section titled “Switch an existing installation to the compact storage”Done by the administrator, once per system, when documents were uploaded to the Document Grounding Hub before the compact storage. A new installation needs nothing.
Step 1. Deploy the new skybfryai_rag_m. Then set PY_RAG_M_EMB_STORAGE to ROWS and PY_RAG_M_VECTOR_SEARCH to EXACT, and restart py_rag_m, as Set or change a value describes. The search then reads the vectors stored before. Until this restart, it does not find them.
Step 2. In SAP HANA Database Explorer, open the SQL console of the HDI container of the RAG module, hdi_db_rag_m (schema SKYBFRYAI_RAG_M), and run:
CALL "proc.migrate_emb_pivot"();The call copies the vectors of the chunks into the compact storage and writes their masks, in portions of 20,000 chunks, each committed. Run one call at a time. On a test system with about 240,000 chunks, the vectors took about 23 minutes and the masks 34 seconds.
Step 3. Set PY_RAG_M_EMB_STORAGE to PIVOT and restart py_rag_m.
Step 4. Run the call of Step 2 once more. It moves the chunks uploaded between Step 2 and Step 3.
Step 5. Check its result: CHUNKS_LEFT and MASKS_LEFT must be 0. If they are not, run the call again: a new call continues where the last one stopped.
Step 6. Set PY_RAG_M_VECTOR_SEARCH to MASK and restart py_rag_m. At start, it logs no error about chunks that its search cannot find.
The call has two optional parameters: the number of chunks in a portion (default 20,000), and the largest number of portions in one call (default 0: until no chunk is left). For example, CALL "proc.migrate_emb_pivot"(20000, 5); moves at most five portions.
Measured effect
Section titled “Measured effect”| Measurement | Before | Now |
|---|---|---|
| Space for the vectors of 240,836 chunks | 5,213 MB (ROWS) |
599 MB (PIVOT, masks included) |
| Vector search in SAP HANA, one document of 232,900 chunks | 8.1 s, 36 s CPU, 654 MB (EXACT) |
3.2 s, 15 s CPU, 623 MB (MASK) |
| Search request, 13 queries to that document, mean | 8.9 s (EXACT) |
5.4 s (MASK) |
| Search request, 100 queries to two small documents, mean | 1.1 s | 1.1 s (under 50,000 chunks the search is exact) |
300 queries to 17 documents in four scopes, MASK |
— | Answer found for 264 of 279; over 50,000 chunks, for 62 of 64 (the exact search misses the other 2 too) |
Measured on a test system with the embedding model bge-m3, 1,024 values per vector. The SAP HANA times are of the second call, with the plan already prepared. The means of the search requests leave out the first query of a run, which also opens the connection.