mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-25 16:13:25 +00:00
docs: add vikingdb docstrings(#19016)
Co-authored-by: gaoyuan <gaoyuan.20001218@bytedance.com>
This commit is contained in:
parent
0e0030f494
commit
ef9813dae6
@ -15,6 +15,22 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class VikingDBConfig(object):
|
class VikingDBConfig(object):
|
||||||
|
"""vikingdb connection config
|
||||||
|
|
||||||
|
See the following documentation for details:
|
||||||
|
https://www.volcengine.com/docs/6459/1167770
|
||||||
|
|
||||||
|
Attribute:
|
||||||
|
host(str):The access address of the vector database server
|
||||||
|
that the client needs to connect to.
|
||||||
|
region(str):"cn-shanghai" or "cn-beijing"
|
||||||
|
ak(str):Access Key ID, security credentials for accessing
|
||||||
|
Volcano Engine services.
|
||||||
|
sk(str):Secret Access Key, security credentials for accessing
|
||||||
|
Volcano Engine services.
|
||||||
|
scheme(str):http or https, defaulting to http.
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, host="host", region="region", ak="ak", sk="sk", scheme="http"): # type: ignore[no-untyped-def]
|
def __init__(self, host="host", region="region", ak="ak", sk="sk", scheme="http"): # type: ignore[no-untyped-def]
|
||||||
self.host = host
|
self.host = host
|
||||||
self.region = region
|
self.region = region
|
||||||
@ -24,6 +40,13 @@ class VikingDBConfig(object):
|
|||||||
|
|
||||||
|
|
||||||
class VikingDB(VectorStore):
|
class VikingDB(VectorStore):
|
||||||
|
"""vikingdb as a vector store
|
||||||
|
|
||||||
|
In order to use this you need to have a database instance.
|
||||||
|
See the following documentation for details:
|
||||||
|
https://www.volcengine.com/docs/6459/1167774
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
embedding_function: Embeddings,
|
embedding_function: Embeddings,
|
||||||
@ -150,6 +173,7 @@ class VikingDB(VectorStore):
|
|||||||
batch_size: int = 1000,
|
batch_size: int = 1000,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> List[str]:
|
) -> List[str]:
|
||||||
|
"""Insert text data into VikingDB."""
|
||||||
try:
|
try:
|
||||||
from volcengine.viking_db import Data
|
from volcengine.viking_db import Data
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -200,6 +224,7 @@ class VikingDB(VectorStore):
|
|||||||
params: Optional[dict] = None,
|
params: Optional[dict] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> List[Document]:
|
) -> List[Document]:
|
||||||
|
"""Perform a similarity search against the query string."""
|
||||||
res = self.similarity_search_with_score(query=query, params=params, **kwargs)
|
res = self.similarity_search_with_score(query=query, params=params, **kwargs)
|
||||||
return [doc for doc, _ in res]
|
return [doc for doc, _ in res]
|
||||||
|
|
||||||
@ -209,6 +234,7 @@ class VikingDB(VectorStore):
|
|||||||
params: Optional[dict] = None,
|
params: Optional[dict] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> List[Tuple[Document, float]]:
|
) -> List[Tuple[Document, float]]:
|
||||||
|
"""Perform a search on a query string and return results with score."""
|
||||||
embedding = self.embedding_func.embed_query(query)
|
embedding = self.embedding_func.embed_query(query)
|
||||||
|
|
||||||
res = self.similarity_search_with_score_by_vector(
|
res = self.similarity_search_with_score_by_vector(
|
||||||
@ -222,6 +248,7 @@ class VikingDB(VectorStore):
|
|||||||
params: Optional[dict] = None,
|
params: Optional[dict] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> List[Document]:
|
) -> List[Document]:
|
||||||
|
"""Perform a similarity search against the query string."""
|
||||||
res = self.similarity_search_with_score_by_vector(
|
res = self.similarity_search_with_score_by_vector(
|
||||||
embedding=embedding, params=params, **kwargs
|
embedding=embedding, params=params, **kwargs
|
||||||
)
|
)
|
||||||
@ -233,6 +260,7 @@ class VikingDB(VectorStore):
|
|||||||
params: Optional[dict] = None,
|
params: Optional[dict] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> List[Tuple[Document, float]]:
|
) -> List[Tuple[Document, float]]:
|
||||||
|
"""Perform a search on a query string and return results with score."""
|
||||||
if self.collection is None:
|
if self.collection is None:
|
||||||
logger.debug("No existing collection to search.")
|
logger.debug("No existing collection to search.")
|
||||||
return []
|
return []
|
||||||
@ -277,6 +305,7 @@ class VikingDB(VectorStore):
|
|||||||
params: Optional[dict] = None,
|
params: Optional[dict] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> List[Document]:
|
) -> List[Document]:
|
||||||
|
"""Perform a search and return results that are reordered by MMR."""
|
||||||
embedding = self.embedding_func.embed_query(query)
|
embedding = self.embedding_func.embed_query(query)
|
||||||
return self.max_marginal_relevance_search_by_vector(
|
return self.max_marginal_relevance_search_by_vector(
|
||||||
embedding=embedding,
|
embedding=embedding,
|
||||||
@ -294,6 +323,7 @@ class VikingDB(VectorStore):
|
|||||||
params: Optional[dict] = None,
|
params: Optional[dict] = None,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> List[Document]:
|
) -> List[Document]:
|
||||||
|
"""Perform a search and return results that are reordered by MMR."""
|
||||||
if self.collection is None:
|
if self.collection is None:
|
||||||
logger.debug("No existing collection to search.")
|
logger.debug("No existing collection to search.")
|
||||||
return []
|
return []
|
||||||
@ -361,6 +391,7 @@ class VikingDB(VectorStore):
|
|||||||
drop_old: bool = False,
|
drop_old: bool = False,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
):
|
):
|
||||||
|
"""Create a collection, indexes it and insert data."""
|
||||||
if connection_args is None:
|
if connection_args is None:
|
||||||
raise Exception("VikingDBConfig does not exists")
|
raise Exception("VikingDBConfig does not exists")
|
||||||
vector_db = cls(
|
vector_db = cls(
|
Loading…
Reference in New Issue
Block a user