Skip to content

Vector Store Development ​

This section covers how to develop custom vector store plugins to integrate new vector databases into Astrsomn.

Overview ​

Astrsomn's vector store extension involves three core interfaces:

InterfaceResponsibility
VecDriverVector driver entry point — manages data source connections and metadata
VecSourceVector data source — manages connection lifecycle and Store creation
VecStoreVector store — provides document CRUD operations

Extend AbstractVecDriver for VecDriver, then implement VecSource and VecStore separately.

Development Steps ​

1. Create Maven Module ​

xml
<project>
    <groupId>com.astrsomn</groupId>
    <artifactId>astrsomn-vector-custom</artifactId>
    <version>0.2.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.astrsomn</groupId>
            <artifactId>astrsomn-api-runtime</artifactId>
            <version>0.2.0-SNAPSHOT</version>
        </dependency>

        <!-- Vector database client SDK -->
    </dependencies>
</project>

2. Implement VecDriver ​

Extend AbstractVecDriver:

java
package com.astrsomn.vector.custom;

import com.astrsomn.api.runtime.common.langchain.extension.vector.AbstractVecDriver;
import com.astrsomn.api.runtime.common.langchain.extension.vector.VecSource;
import com.astrsomn.api.vector.entity.AiVecDriverEntity;
import com.astrsomn.api.vector.entity.AiVecSourceEntity;

public class CustomVecDriver extends AbstractVecDriver {

    @Override
    public String getExtensionKey() {
        return "CUSTOM";  // Unique driver identifier
    }

    @Override
    public VecSource bindSource(AiVecSourceEntity source) {
        // Bind source entity to a concrete VecSource implementation
        return new CustomVecSource(source);
    }

    @Override
    public AiVecDriverEntity getDriverEntity() {
        // Return driver metadata: name, parameter definitions (HOST, PORT, TOKEN)
        AiVecDriverEntity entity = new AiVecDriverEntity();
        entity.setName("Custom Vector Store");
        entity.setProvider("CUSTOM");
        entity.setParams(defineDriverParams());
        return entity;
    }
}

3. Implement VecSource ​

VecSource manages the connection to the vector database:

java
package com.astrsomn.vector.custom;

import com.astrsomn.api.runtime.common.langchain.extension.vector.VecSource;
import com.astrsomn.api.runtime.common.langchain.extension.vector.VecStore;
import com.astrsomn.api.vector.entity.AiVecSourceEntity;
import com.astrsomn.api.vector.entity.AiVecStoreEntity;

public class CustomVecSource implements VecSource {

    private final AiVecSourceEntity sourceEntity;
    private CustomClient client;

    public CustomVecSource(AiVecSourceEntity sourceEntity) {
        this.sourceEntity = sourceEntity;
    }

    @Override
    public AiVecSourceEntity getEntity() {
        return sourceEntity;
    }

    @Override
    public boolean testConnection() {
        try {
            client.ping();
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public void shutdown() {
        if (client != null) {
            client.close();
        }
    }

    @Override
    public VecStore openStore(AiVecStoreEntity store) {
        return new CustomVecStore(this, store);
    }
}

4. Implement VecStore ​

VecStore provides actual document storage operations:

java
package com.astrsomn.vector.custom;

import com.astrsomn.api.runtime.common.langchain.extension.vector.VecSource;
import com.astrsomn.api.runtime.common.langchain.extension.vector.VecStore;
import com.astrsomn.api.vector.entity.AiVecStoreEntity;
import dev.langchain4j.data.segment.TextSegment;
import dev.langchain4j.store.embedding.EmbeddingStore;

public class CustomVecStore implements VecStore {

    private final CustomVecSource source;
    private final AiVecStoreEntity storeEntity;

    public CustomVecStore(CustomVecSource source, AiVecStoreEntity storeEntity) {
        this.source = source;
        this.storeEntity = storeEntity;
    }

    @Override
    public VecSource getSource() { return source; }

    @Override
    public AiVecStoreEntity getEntity() { return storeEntity; }

    @Override
    public void createCollection() {
        // Create vector collection
    }

    @Override
    public void dropCollection() {
        // Drop vector collection
    }

    @Override
    public boolean exists() {
        return false;
    }

    @Override
    public long count() {
        return 0;
    }

    @Override
    public EmbeddingStore<TextSegment> getEmbeddingStore() {
        // Core method — returns LangChain4j EmbeddingStore implementation
        // All document add/search/delete operations flow through this
        return embeddingStore;
    }
}

Core Method: getEmbeddingStore()

getEmbeddingStore() returns a LangChain4j EmbeddingStore<TextSegment> implementation. This is the key bridge between the framework and the vector database — all document addition, search, and deletion goes through this interface. If your database already has a LangChain4j integration (Qdrant, Milvus, Chroma), you can use it directly.

5. Create Extension Descriptor ​

java
package com.astrsomn.vector.custom;

import com.astrsomn.starter.system.AstroExtensionDescriptor;
import com.astrsomn.api.system.entity.SystemExtensionEnum;

public class CustomVecExtensionDescriptor extends AstroExtensionDescriptor {

    @Override
    public String getExtensionKey() { return "CUSTOM"; }

    @Override
    public String getExtensionCode() { return "CUSTOM"; }

    @Override
    public SystemExtensionEnum.ExtensionTypeEnum getExtensionType() {
        return SystemExtensionEnum.ExtensionTypeEnum.VECTOR_STORE;
    }
}

6. Register SPI ​

Create two files under src/main/resources/META-INF/services/:

File 1: com.astrsomn.api.runtime.common.langchain.extension.vector.VecDriver

com.astrsomn.vector.custom.CustomVecDriver

File 2: com.astrsomn.api.runtime.common.langchain.extension.AstroExtensionDescriptor

com.astrsomn.vector.custom.CustomVecExtensionDescriptor

Interface Reference ​

VecDriver ​

Package: com.astrsomn.api.runtime.common.langchain.extension.vector

MethodReturn TypeDescription
getExtensionKey()StringUnique driver identifier
bindSource(AiVecSourceEntity)VecSourceBinds source entity to a VecSource
getDriverEntity()AiVecDriverEntityDriver metadata (name, parameter definitions)
getVersion()StringVersion (default: "1.0.0")
getAuthor()StringAuthor (default: "Astrsomn")

VecSource ​

Package: com.astrsomn.api.runtime.common.langchain.extension.vector

MethodReturn TypeDescription
getEntity()AiVecSourceEntitySource entity
testConnection()booleanTest connection health
shutdown()voidClose connection, release resources
openStore(AiVecStoreEntity)VecStoreOpen or create a store

VecStore ​

Package: com.astrsomn.api.runtime.common.langchain.extension.vector

MethodReturn TypeDescription
getSource()VecSourceParent data source
getEntity()AiVecStoreEntityStore entity
createCollection()voidCreate collection
dropCollection()voidDrop collection
exists()booleanCheck if collection exists
count()longDocument count
getEmbeddingStore()EmbeddingStore<TextSegment>Core — returns LangChain4j store

Build & Deploy ​

bash
mvn clean package -DskipTests

cp target/astrsomn-vector-custom-0.2.0-SNAPSHOT.jar /path/to/astrsomn/plugins/

Reference Implementations ​

  • Qdrant — astrsomn-plugins/astrsomn-vector/astrsomn-vector-qdrant/
  • Milvus — astrsomn-plugins/astrsomn-vector/astrsomn-vector-milvus/
  • Chroma — astrsomn-plugins/astrsomn-vector/astrsomn-vector-chroma/
  • Redis — astrsomn-plugins/astrsomn-vector/astrsomn-vector-redis/