@mi8y/cap-agents-cds-vectorstore
A LangChain vector store whose documents and embeddings are CDS entities, so retrieval runs as a CDS query against the database the CAP service is already bound to.
Retrieval inside a CAP application has to put the chunks and their embeddings somewhere, and LangChain's retrieval APIs expect a VectorStore behind them. CDSVectorStore is that implementation over CDS: cds add agent-cds-vectorstore generates Documents and DocumentMetadata entities in the plugin.langchain.vectorstore namespace with a Vector(1536) embedding sized for text-embedding-3-small, and both are aspects, so a project that wants a second store or another dimension declares its own entities and passes their names to the constructor. similaritySearch, similaritySearchWithScore, maxMarginalRelevanceSearch and asRetriever are the read side, with cosine similarity, a threshold that defaults to 0.75, and metadata filters over direct equality, $eq, $ne, $in and $notIn. Turning text into a vector is the caller's: an Embeddings implementation is passed to the constructor, and nothing here splits a long document into chunks.
Facts
Where it sits
Who is behind it
In the atlas: maintains 6, contributes to 6@anselm94Mi8Y TechnologiesMi8Y TechnologiesMaintains this
In the atlas: maintains 6@mi8ymaintainers
Before choosing this
Conditions
LicenceSAP Developer License Agreement 3.2 CAP§ 3from Retrieval-augmented generationCovered SAP materials or a covered CAP customer application are included in training data, model development or model refinement.
- § 3 Artificial Intelligence Training. The agreement prohibits use of the covered materials and customer applications for training artificial-intelligence models or systems.
Retrieval and inference are not automatically AI training. The section becomes relevant if the indexed or retrieved covered material is instead used for training, developing or refining the model or system.
SAP Developer License Agreement 3.2 CAP →What it declares
Every artifact
- Type
- Package
- Origin
- Independently maintained
- Runtime
- Node.js
As a package
- Declared for
- >=10
- Type declarations
- declared
- Where it runs
- does not say
- Distributed through
- does not say
Connections
Grounding a model's answer in data retrieved at question time
Download
Install
npm add @mi8y/cap-agents-cds-vectorstoreDerived from the package name. No recipe recorded; the README has the configuration.
README
quoted from mi8y/cap-agents-addons under MIT, read@mi8y/cap-agents-cds-vectorstore
A simple LangChain vector store for SAP CAP applications.
This package gives you a VectorStore implementation backed by CAP CDS entities, so you can store embeddings and documents in your CAP application's database and use standard LangChain retrieval APIs for RAG and semantic search.
Installation
npm install @mi8y/cap-agents-cds-vectorstore
Then register the CDS model in your CAP project:
cds add agent-cds-vectorstore
This creates db/agent-cds-vectorstore.cds with two concrete entities (Documents and DocumentMetadata) under the default plugin.langchain.vectorstore namespace. The entities implement the package's reusable aspects with a default Vector(1536) embedding size (matching OpenAI text-embedding-3-small).
Requires:
@sap/cds >= 10@langchain/core >= 1
What it adds
The plugin provides two reusable CDS aspects under the plugin.langchain.vectorstore namespace:
VectorDocument— defines the shape for stored content and embeddingsVectorDocumentMetadata— defines the shape for document metadata entries
Running cds add agent-cds-vectorstore generates default concrete entities implementing these aspects.
At runtime, CDSVectorStore reads and writes through CAP CDS, so it fits naturally into CAP applications and their existing database setup.
Usage
import { OpenAIEmbeddings } from "@langchain/openai";
import { CDSVectorStore } from "@mi8y/cap-agents-cds-vectorstore";
const embeddings = new OpenAIEmbeddings({
model: "text-embedding-3-small",
});
const vectorStore = new CDSVectorStore(embeddings, {
name: "knowledge-base",
});
await vectorStore.addDocuments([
{
id: "doc-1",
pageContent: "SAP CAP is a framework for building enterprise applications.",
metadata: { source: "docs", topic: "cap" },
},
{
id: "doc-2",
pageContent:
"LangChain helps build LLM apps with retrieval, tools, and agents.",
metadata: { source: "docs", topic: "langchain" },
},
]);
const results = await vectorStore.similaritySearch("What is SAP CAP?", 2);
console.log(results);
Customizing entities
1. Customizing embedding size
The default entities generated by cds add use Vector(1536). To use a different embedding size, just override the embedding field in your own concrete entity implementing the VectorDocument aspect.
...
entity Documents : managed, VectorDocument {
embedding : Vector(3072); // ---> for 'text-embedding-3-large' model
metadata : Composition of many DocumentMetadata
on metadata.document = $self;
}
...
2. Customizing namespace and entity definitions
To use a different namespace or entity definitions (i.e. one definition per vector store), define your own entities implementing the package's aspects:
using { managed } from '@sap/cds/common';
using { VectorDocument, VectorDocumentMetadata } from '@mi8y/cap-agents-cds-vectorstore';
namespace my.app.vectorstore;
/**
Vector store 1: Knowledge Base
*/
entity KnowledgeBaseDocuments : managed, VectorDocument {
embedding : Vector(3072);
metadata : Composition of many DocumentMetadata
on metadata.document = $self;
}
entity KnowledgeBaseDocumentMetadata : VectorDocumentMetadata {
key document : Association to KnowledgeBaseDocuments;
}
/**
Vector store 2: Customer Support
*/
entity CustomerSupportDocuments : managed, VectorDocument {
embedding : Vector(1536);
metadata : Composition of many DocumentMetadata
on metadata.document = $self;
}
entity CustomerSupportDocumentMetadata : VectorDocumentMetadata {
key document : Association to CustomerSupportDocuments;
}
Then pass the custom entity names to CDSVectorStore:
const knowledgebaseVectorStore = new CDSVectorStore(embeddings, {
name: "knowledge-base",
fqnDocumentsEntity: "my.app.vectorstore.KnowledgeBaseDocuments",
fqnDocumentMetadataEntity: "my.app.vectorstore.KnowledgeBaseDocumentMetadata",
});
const customersupportVectorStore = new CDSVectorStore(embeddings, {
name: "customer-support",
fqnDocumentsEntity: "my.app.vectorstore.CustomerSupportDocuments",
fqnDocumentMetadataEntity:
"my.app.vectorstore.CustomerSupportDocumentMetadata",
});
Field names (storeName, id, pageContent, embedding, metadata, name, value, document) are fixed across all implementations.
Use as a retriever
CDSVectorStore implements the standard LangChain vector store interface, so you can turn it into a retriever directly:
const retriever = vectorStore.asRetriever({
k: 2,
});
const docs = await retriever.invoke("Explain CAP");
It also supports:
similaritySearchsimilaritySearchWithScoremaxMarginalRelevanceSearch
Metadata filtering
You can filter results by metadata when retrieving:
const retriever = vectorStore.asRetriever({
k: 2,
filter: {
topic: "cap",
priority: { $in: [2, 3] },
},
});
const docs = await retriever.invoke("framework");
Supported operators:
- direct equality, like
{ topic: "cap" } $eq— equal to$ne— not equal to$in— match any of the provided values$notIn— exclude any of the provided values
API
new CDSVectorStore(embeddings, config)
Creates a CDS-backed vector store.
Config options:
-
name: stringRequired store name. Use this to isolate one vector store from another in the same database. -
threshold?: numberOptional similarity threshold. Defaults to0.75. -
fqnDocumentsEntity?: stringFully-qualified CDS entity name for the documents table. Defaults toplugin.langchain.vectorstore.Documents. -
fqnDocumentMetadataEntity?: stringFully-qualified CDS entity name for the metadata table. Defaults toplugin.langchain.vectorstore.DocumentMetadata.
Static helpers
CDSVectorStore.fromTexts(texts, metadatas, embeddings, config)CDSVectorStore.fromDocuments(docs, embeddings, config)CDSVectorStore.fromExistingIndex(embeddings, config)
Notes
- Document IDs are preserved if you provide them.
- If no ID is provided, the store generates one.
- The package uses cosine similarity for retrieval.
- The CDS model uses CAP's
Vectortype for embeddings. - To extend the default embedding size, define your own concrete entities implementing the package's aspects.
License
History
Others providing
Compare all 9 on the RAG on CDS page →- SAP AI CoreSAP AI CoreSAP's AI service on BTP: the runtime for AI assets, and through the Generative AI Hub inside it the access to foundation models, the orchestration service with its templating, masking, filtering and grounding modules, the Prompt Registry and Document Grounding.sap official, btpAI runtime on BTP with the Generative AI Hub
- SAP HANA CloudSAP HANA CloudThe managed database under most of this: CAP's default target, the store Datasphere and Analytics Cloud sit on, and a service with plans and components.sap official, btpManaged SAP HANA database service on BTP
- @cap-js/ai@cap-js/aiOut-of-the-box value-help recommendations powered by SAP RPT-1, SAP AI Core as a standard CAP service, and an experimental local embedding model behind SQLite's vector functions.sap official, capValue-help recommendations and SAP AI Core as a CAP service
- cap-llm-plugincap-llm-pluginGenerative AI in a CAP application with the sensitive fields anonymised through SAP HANA before the prompt leaves, so the model never sees the confidential half.independent, capGenerative AI in CAP with fields anonymised through SAP HANA
- @mi8y/cap-agents-aicore-vectorstore@mi8y/cap-agents-aicore-vectorstoreA LangChain vector store backed by SAP AI Core Document Grounding: the collection holds the documents and makes the embeddings, and the CAP application stores no vectors of its own.independent, capLangChain vector store on SAP AI Core Document Grounding
- @sap/cds@sap/cdsThe CAP Node.js runtime, which compiles the CDS model, serves the services declared in it, answers generic requests before any handler runs, and loads every cds-plugin.sap official, capCAP Node.js runtime
- @saptarishi/cds-plugin-llm@saptarishi/cds-plugin-llmA CAP service kind that puts eleven model providers behind one chat, stream, embed and batch interface, so which backend a service calls is a profile in package.json rather than a change to the handler.independent, capCAP service kind putting eleven model providers behind one API
- @saptarishi/cds-plugin-vector-hana@saptarishi/cds-plugin-vector-hanaVector storage and similarity search on SAP HANA from CAP, packaged as a plugin so the embedding column and the query are modelled rather than hand-written.independent, capVector storage and similarity search on SAP HANA from CAP
Details
Sources
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
History in the atlas
- First seen.
For your agent
- Ref
artifact:mi8y-cap-agents-cds-vectorstore- JSON
- /artifacts/mi8y-cap-agents-cds-vectorstore.json
- MCP
- Connecting an agent