Source code for langchain.vectorstores.dingo
from __future__ import annotations
import logging
import uuid
from typing import Any, Iterable, List, Optional, Tuple
import numpy as np
from langchain.docstore.document import Document
from langchain.schema.embeddings import Embeddings
from langchain.schema.vectorstore import VectorStore
from langchain.vectorstores.utils import maximal_marginal_relevance
logger = logging.getLogger(__name__)
[docs]class Dingo(VectorStore):
    """`Dingo` vector store.
    To use, you should have the ``dingodb`` python package installed.
    Example:
        .. code-block:: python
            from langchain.vectorstores import Dingo
            from langchain.embeddings.openai import OpenAIEmbeddings
            embeddings = OpenAIEmbeddings()
            dingo = Dingo(embeddings, "text")
    """
[docs]    def __init__(
        self,
        embedding: Embeddings,
        text_key: str,
        *,
        client: Any = None,
        index_name: Optional[str] = None,
        host: Optional[List[str]] = None,
        user: str = "root",
        password: str = "123123",
        self_id: bool = False,
    ):
        """Initialize with Dingo client."""
        try:
            import dingodb
        except ImportError:
            raise ImportError(
                "Could not import dingo python package. "
                "Please install it with `pip install dingodb."
            )
        host = host if host is not None else ["172.20.31.10:13000"]
        # collection
        if client is not None:
            dingo_client = client
        else:
            try:
                # connect to dingo db