fed8b2eed7
Backend release / release (push) Waiting to run
Bandit Security Scan / bandit_scan (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / build (linux/amd64, ubuntu-latest, amd64) (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Waiting to run
Build and push multi-arch DocsGPT Docker image / manifest (push) Blocked by required conditions
Build and push DocsGPT FE Docker image for development / build (linux/amd64, ubuntu-latest, amd64) (push) Waiting to run
Build and push DocsGPT FE Docker image for development / build (linux/arm64, ubuntu-24.04-arm, arm64) (push) Waiting to run
Build and push DocsGPT FE Docker image for development / manifest (push) Blocked by required conditions
Python linting / ruff (push) Waiting to run
Run python tests with pytest / Run tests and count coverage (3.12) (push) Waiting to run
React Widget Build / build (push) Waiting to run
42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
from typing import List, Optional
|
|
from uuid import uuid4
|
|
|
|
|
|
from application.core.settings import settings
|
|
from application.vectorstore.base import BaseVectorStore
|
|
|
|
|
|
class MilvusStore(BaseVectorStore):
|
|
def __init__(self, source_id: str = "", embeddings_key: str = "embeddings"):
|
|
super().__init__()
|
|
from langchain_milvus import Milvus
|
|
|
|
connection_args = {
|
|
"uri": settings.MILVUS_URI,
|
|
"token": settings.MILVUS_TOKEN,
|
|
}
|
|
self._docsearch = Milvus(
|
|
embedding_function=self._get_embeddings(settings.EMBEDDINGS_NAME, embeddings_key),
|
|
collection_name=settings.MILVUS_COLLECTION_NAME,
|
|
connection_args=connection_args,
|
|
)
|
|
self._source_id = source_id
|
|
|
|
def search(self, question, k=2, *args, **kwargs):
|
|
# Drop the per-source score_threshold (unsupported here) so it is safely
|
|
# ignored instead of being forwarded into the langchain call.
|
|
kwargs.pop("score_threshold", None)
|
|
expr = f"source_id == '{self._source_id}'"
|
|
return self._docsearch.similarity_search(query=question, k=k, expr=expr, *args, **kwargs)
|
|
|
|
def add_texts(self, texts: List[str], metadatas: Optional[List[dict]], *args, **kwargs):
|
|
ids = [str(uuid4()) for _ in range(len(texts))]
|
|
|
|
return self._docsearch.add_texts(texts=texts, metadatas=metadatas, ids=ids, *args, **kwargs)
|
|
|
|
def save_local(self, *args, **kwargs):
|
|
pass
|
|
|
|
def delete_index(self, *args, **kwargs):
|
|
pass
|