npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mi8y/cap-agents-cds-vectorstore

v0.2.0

Published

CDS Plugin for building vector retrieval in LangGraph/LangChain/DeepAgents - Vector Store

Downloads

12

Readme

@mi8y/cap-agents-cds-vectorstore

npm version License: MIT monthly downloads

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 >= 9
  • @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 embeddings
  • VectorDocumentMetadata — 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:

  • similaritySearch
  • similaritySearchWithScore
  • maxMarginalRelevanceSearch

Metadata filtering

You can filter results by metadata when retrieving:

const retriever = vectorStore.asRetriever({
  k: 2,
  filter: {
    topic: "cap",
    priority: { $gte: 2 },
  },
});

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: string Required store name. Use this to isolate one vector store from another in the same database.

  • threshold?: number Optional similarity threshold. Defaults to 0.75.

  • fqnDocumentsEntity?: string Fully-qualified CDS entity name for the documents table. Defaults to plugin.langchain.vectorstore.Documents.

  • fqnDocumentMetadataEntity?: string Fully-qualified CDS entity name for the metadata table. Defaults to plugin.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 Vector type for embeddings.
  • To extend the default embedding size, define your own concrete entities implementing the package's aspects.

License

MIT License