PackagePackagetypeA library you install and call yourself.See every one →What this type is →independently maintainedindependently maintainedoriginPublished by one person or a small company outside SAP. Says nothing about quality; the readings say that.See every one →

zvdb

A vector database implemented entirely in ABAP, which stores quantised vectors and retrieves the document chunks relevant to a prompt by brute-force dot product.

The ABAP Vector Search Library keeps the store and the search for a chat-with-your-documents scenario inside ABAP, rather than relying on an external vector database: documents are sliced into chunks, and the semantically relevant ones are injected into the user's prompt. Vectors are held quantised and compared by a brute-force dot product, which the README reports at about 20μs per comparison, or some 50,000 vectors a second. Quantisation cuts a 1536-dimension vector from 12,288 bytes to 192, so 1GB holds 5.5 million quantised vectors against 87,000 unquantised ones. The library is self-contained for that core; generating the embeddings is a separate job, and for it the README points at the Microsoft AI SDK for SAP, which it calls the OpenAI ABAP SDK.

Facts

Last pushLicenceMIT

Where it sits

Lives in
Provides
Retrieval-augmented generationABAPRetrieval-augmented generationcapabilityGrounding a model's answer in data retrieved at question time: text split into chunks, each chunk embedded as a vector, and the chunks nearest to the question placed into the prompt. Semantic search is the same retrieval with a person reading the matches, and fine-tuning changes the model's weights, not its input.
Requires
abapGitabapGitartifactInstalls the repository into the ABAP system; the README gives abapGit as the install method.

Who is behind it

Alice V.Alice V.PersonMaintains this
In the atlas: maintains 6, contributes to 12
@oisee
maintainerLars HvamPersonContributes to this
In the atlas: maintains 13, contributes to 92, wrote 1
@larshp
1 contributor

What it declares

Every artifact

Type
Package
Origin
Independently maintained

As a package

Where it runs
Inside its host
Distributed through
abapGit

Connections2

README

quoted from oisee/zvdb under MIT, read
oisee/zvdb/README.mdOn GitHub

ABAP Vector Search Library

The ABAP Vector Search Library is a Vector Database developed entirely in ABAP, designed to offer an independent solution without relying on external vector databases. It's particularly tailored for the "chat with your documents" scenario, enabling the slicing of documents into manageable chunks and the injection of these semantically relevant segments into user prompts. This approach facilitates an interactive and efficient method for handling and responding to user queries within document-based systems.

The library employs the RAG (Retrieval Augmented Generation) technique, which is integral to its functionality, enhancing the interaction between users and document data.

RAG is the technique that is powering the “chat with your documents” scenario:

  • Slice documents into chunks
  • Inject semantically relevant chunks into the Prompt:
Considering only information below:
###
{chunk01}
{chunk02}
{chunk03}
###
please provide response to the following request: 
{query from user}

How it works? Why it works? O_O

Explained here:

Stats

Some stats:

Optimization: initially it was ~3000μs for one floating-point unquantized comparison, using 1b quantization and bitwise operation it was optimized down to ~20μs, so we easily can do dot product (i.e.: do brute force search): for ~50000 vectors per second.

For RAG with the context window of 32k it is more than enough ^_^

Memory footprint

Floating point variable (f) takes 8 bytes in memory, one floating-point vector: 1536 * 8 = 12288 bytes (~12kb). Quantized vector takes 192 bytes.

1GB gives us 87 thousands fp-vectors or 5.5 millions quantized vectors.

Memory footprint is 64 times less. Nice! =)

Sample Usage

Query DB:
show code...
    DATA(lo_lib) = zcl_vdb_002_lib=>new( ). "instantiate library

    DATA(ls_v) = lo_lib->read_vector( id ). "read vector from DB by its GUID
    DATA(lt_q) = lo_lib->query( ls_v-q1b ). "query DB with the quantized 1536-dimensional vector

    cl_demo_output=>display( lt_q ). "observe ranked result
Answer with RAG:
show code...
    DATA(lo_e) = zcl_vdb_002_embedding_full=>new( ). "using https://github.com/microsoft/aisdkforsapabap

    DATA(lv_text) = 'Answer to the Ultimate Question of Life, the Universe, and Everything'.

* Embed and save text, retrieve ID
    DATA(lv_id_q) = lo_e->embed_and_save( lv_text )-id.
    COMMIT WORK AND WAIT.

* Generate an answer as vector
    DATA(lx_a) = lo_e->answer( lv_text ).
*--------------------------------------------------------------------*
    DATA(lo_lib) = zcl_vdb_002_lib=>new( ).
    DATA(lt_q) = lo_lib->query_by_id( lv_id_q ). "get chunks semantically close to the question
* Query for answers
    DATA(lt_a) = lo_lib->query( lx_a ).          "get chunks semantically close to the "modelled answer"

* Combine, sort, and remove duplicates from query results
    DATA(lt_all) = lt_q.
    APPEND LINES OF lt_a TO lt_all.
    SORT lt_all BY id.
    DELETE ADJACENT DUPLICATES FROM lt_all.

* Prepare for RAG (Retrieve and Generate) method
    DATA: lv_prompt TYPE string.
    DATA: lt_used TYPE zcl_vdb_002_lib=>tt_vector.

* Execute RAG with text and combined results, get prompt and used vectors
    DATA(lv_rag_answer) = lo_e->rag(
                            EXPORTING iv_ = lv_text
                                      it_ = lt_all
                            IMPORTING ev_prompt = lv_prompt
                                      et_used   = lt_used
    ).

    cl_demo_output=>write( lv_rag_answer ). "observe RAG answer
    cl_demo_output=>write( lv_prompt ).     "check out the resulting prompt
    cl_demo_output=>display(  ).

Dependencies

The library is self-contained for the core functionality of the Vector Search. However if you want to generate embeddings, you might want to install this OpenAI ABAP SDK.

To instantiate SDK you might need to use your own private keys, you can store them locally in a simple key-value .env file, something like:

#https://<subdomain>.openai.azure.com/openai/deployments/<api_dep>/chat/completions?api-version=2023-07-01-preview
#https://<subdomain>.openai.azure.com/openai/deployments/<api_dep>/chat/completions?api-version=<API_VER>
API_URL=https://<subdomain>.openai.azure.com/
API_VER=2023-07-01-preview
API_KEY=<xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
API_DEP=<deployment_id>
API_DEP_EMBED=<deployment_id_embedding_model>
show code...
    DATA(lo_) = zcl_vdb_000_dotenv=>new( lv_path ).
    DATA(lv_api_key) = cut->v( 'API_KEY' ).

    data(ls_) = VALUE ts_env(
      api_url       = lo_->v( k = 'API_URL' )
      api_ver       = lo_->v( k = 'API_VER' )
      api_key       = lo_->v( k = 'API_KEY' )
      api_dep       = lo_->v( k = 'API_DEP' )
      api_dep_embed = lo_->v( k = 'API_DEP_EMBED' )
    ).

Installation

Install this repository using abapGit.

  • Run the report zvdb_002_demo_01_upload to upload sample vector embeddings from sample_embeddings.tsv.
  • Now you can use zvdb_002_demo_02_query to query DB.
  • zvdb_002_demo_03_reindex to recalibrate heuristic hyperplane hash and reindex.

© 2023 Alice Vinogradova. For more information, see the LICENSE file in this repository.

MIT, read
Retrieval-augmented generation
  1. SAP AI CoreAI runtime on BTP with the Generative AI Hubfrom BTP/BAIP
  2. SAP HANA CloudManaged SAP HANA database service on BTPfrom BTP/BAIP
  3. @cap-js/aiValue-help recommendations and SAP AI Core as a CAP servicefrom CAP
  4. cap-llm-pluginGenerative AI in CAP with fields anonymised through SAP HANAfrom CAP
  5. @mi8y/cap-agents-aicore-vectorstoreLangChain vector store on SAP AI Core Document Groundingfrom CAP
  6. @mi8y/cap-agents-cds-vectorstoreLangChain vector store with CDS entities for embeddingsfrom CAP
  7. @sap/cdsCAP Node.js runtimefrom CAP
  8. @saptarishi/cds-plugin-llmCAP service kind putting eleven model providers behind one APIfrom CAP
  9. @saptarishi/cds-plugin-vector-hanaVector storage and similarity search on SAP HANA from CAPfrom CAP
  10. sap-knowledge-pipelinePython library turning OData or HANA records into chunked documentsfrom BTP/BAIP

Details

Sources3
Added by handdiscovered herechecked
github.com/oisee/zvdbtree, pushes, contributors, CIchecked
README.mdquoted, and what the entry declareschecked

Sources are graph entities: the same page may back several entries, and an unreachable source flags every row that rests on it.

Compatibility and provenance
discovered viaAdded by hand
first seen in the atlas
ecosystem and domainabap, ai-and-agents
abaplint
issues under its own abaplint configuration0
lines4,023
statements2,759
objects22
files20
analysed, main
abaplint version2.120.84
Contributors1

From the repository’s contributor list, .

History in the atlas1
  1. First seen.
For your agent