Source code for langchain_community.vectorstores.semadb
from typing import Any, Iterable, List, Optional, Tuple
from uuid import uuid4
import numpy as np
import requests
from langchain_core.documents import Document
from langchain_core.embeddings import Embeddings
from langchain_core.utils import get_from_env
from langchain_core.vectorstores import VectorStore
from langchain_community.vectorstores.utils import DistanceStrategy
[docs]class SemaDB(VectorStore):
    """`SemaDB` vector store.
    This vector store is a wrapper around the SemaDB database.
    Example:
        .. code-block:: python
            from langchain_community.vectorstores import SemaDB
            db = SemaDB('mycollection', 768, embeddings, DistanceStrategy.COSINE)
    """
    HOST = "semadb.p.rapidapi.com"
    BASE_URL = "https://" + HOST
[docs]    def __init__(
        self,
        collection_name: str,
        vector_size: int,
        embedding: Embeddings,
        distance_strategy: DistanceStrategy = DistanceStrategy.EUCLIDEAN_DISTANCE,
        api_key: str = "",
    ):
        """Initialise the SemaDB vector store."""
        self.collection_name = collection_name
        self.vector_size = vector_size
        self.api_key = api_key or get_from_env("api_key", "SEMADB_API_KEY")
        self._embedding = embedding
        self.distance_strategy = distance_strategy
    @property
    def headers(self) -> dict:
        """Return the common headers."""
        return {
            "content-type": "application/json",
            "X-RapidAPI-Key": self.api_key,
            "X-RapidAPI-Host": SemaDB.HOST,
        }