agentleFS
SAPSAP/custom-agentic-cookbook/skills/sap-hana-vector/SKILL.md

sap-hana-vector

Skill9 starsChanged 22 days agoApache-2.0View on GitHub

Use this skill when building RAG on SAP HANA Cloud's vector engine — REAL_VECTOR columns, VECTOR_EMBEDDING() function, cosine search, and the langchain-hana / generative-ai-hub-sdk client paths. Covers ingestion, indexing, and querying patterns.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Run sap-hana-data-prep before this skill.

    line 26
  2. Very specific:

    If prepared/ingestion-contract.yaml is absent or target_shape is not hana_vector, return to sap-hana-data-prep.

    line 33
  3. Distinctive:

    No HNSW index → slow at >10k rows.

    line 75

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

SAP HANA Cloud Vector — RAG patterns

HANA Cloud ships a native vector column type (REAL_VECTOR) and a SQL function VECTOR_EMBEDDING(text, model) that calls AI Core embeddings inline. That means you can ingest, embed, and query without leaving SQL — but the Python clients (langchain-hana / generative-ai-hub-sdk) are usually nicer.

Schema pattern

CREATE TABLE DOCS (
  ID NVARCHAR(64) PRIMARY KEY,
  TEXT NCLOB,
  METADATA NCLOB,                  -- JSON
  EMBEDDING REAL_VECTOR(1536)      -- dim = your embedding model's dim
);

-- Cosine HNSW index — fastest, smallest, default choice.
CREATE HNSW VECTOR INDEX IDX_DOCS_EMB ON DOCS(EMBEDDING) SIMILARITY FUNCTION COSINE_SIMILARITY;

Before ingestion: data preparation

Run sap-hana-data-prep before this skill. It produces the ingestion contract and chunked artifacts this skill consumes:

prepared/chunks.jsonl            -- id, text, metadata per chunk
prepared/ingestion-contract.yaml -- confirms target_shape: hana_vector, embedding_model, pii_handling

If prepared/ingestion-contract.yaml is absent or target_shape is not hana_vector, return to sap-hana-data-prep.

Ingestion via SQL only

INSERT INTO DOCS (ID, TEXT, EMBEDDING)
  VALUES (?, ?, VECTOR_EMBEDDING(?, 'AICORE', 'text-embedding-3-large'));

For region-availability of text-embedding-3-large see sap-sovereign-regions and run recipes/00-develop/00-region-preflight/ — China and KSA need to swap to a multilingual SAP-hosted embedding instead.

Ingestion via Python

from langchain_hana import HanaDB
from gen_ai_hub.proxy.langchain.openai import OpenAIEmbeddings

embeddings = OpenAIEmbeddings(deployment_id=os.environ["EMB_DEPLOYMENT_ID"])
store = HanaDB(connection=hana_conn, embedding=embeddings, table_name="DOCS")

store.add_texts(
    texts=["...chunk 1...", "...chunk 2..."],
    metadatas=[{"source": "doc.pdf", "page": 1}, ...],
)

Query

results = store.similarity_search_with_score("how do I deploy to Kyma?", k=4)

Or as SQL:

SELECT TOP 4 ID, TEXT, COSINE_SIMILARITY(EMBEDDING, VECTOR_EMBEDDING(?, 'AICORE', 'text-embedding-3-large')) AS SCORE
  FROM DOCS ORDER BY SCORE DESC;

Pitfalls

  • Wrong dimension → INSERT fails. Pick the embedding model first, then create the table.
  • No HNSW index → slow at >10k rows. Add the index after the bulk-load, not before.
  • Mixing embedding models without re-indexing → silent quality drop. Pick one and stick to it.
  • Embedding model mismatch with region → run recipes/00-develop/00-region-preflight/ first and cross-check sap-sovereign-regions; China / KSA / NS2 constraints on text-embedding-3-large apply here too.

Verify

SELECT COUNT(*) FROM DOCS WHERE EMBEDDING IS NOT NULL;
-- expect: > 0
SELECT TOP 1 ID, COSINE_SIMILARITY(EMBEDDING, VECTOR_EMBEDDING('hello', 'AICORE', 'text-embedding-3-large')) FROM DOCS;
-- expect: a score in (0, 1)

Cross-references

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.