Download app/retrieval/qdrant_store.py from acpcchatbotadmin/acpcchatbot_testing_first: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/spaces/acpcchatbotadmin/acpcchatbot_testing_first/resolve/main/app/retrieval/qdrant_store.py
- Command line
-
hf download hf://spaces/acpcchatbotadmin/acpcchatbot_testing_first/app/retrieval/qdrant_store.py
-
curl -L -o qdrant_store.py https://huggingface.co/spaces/acpcchatbotadmin/acpcchatbot_testing_first/resolve/main/app/retrieval/qdrant_store.py
1.62 kB
| from qdrant_client import QdrantClient | |
| from langchain_qdrant import QdrantVectorStore, RetrievalMode | |
| from langchain_openai import OpenAIEmbeddings | |
| from app.config import settings | |
| _client: QdrantClient | None = None | |
| _vector_store: QdrantVectorStore | None = None | |
| _embeddings: OpenAIEmbeddings | None = None | |
| def get_qdrant_client() -> QdrantClient: | |
| global _client | |
| if _client is None: | |
| _client = QdrantClient( | |
| url=settings.qdrant_url, | |
| api_key=settings.qdrant_api_key, | |
| timeout=120, | |
| ) | |
| return _client | |
| def get_embeddings() -> OpenAIEmbeddings: | |
| global _embeddings | |
| if _embeddings is None: | |
| _embeddings = OpenAIEmbeddings( | |
| model=settings.embedding_model, | |
| api_key=settings.openai_api_key, | |
| openai_api_base=settings.openai_api_base, | |
| ) | |
| return _embeddings | |
| def get_vector_store() -> QdrantVectorStore: | |
| """Return the singleton QdrantVectorStore connected to the existing collection.""" | |
| global _vector_store | |
| if _vector_store is None: | |
| client = get_qdrant_client() | |
| embeddings = get_embeddings() | |
| # Use DENSE retrieval (existing collection was indexed with dense vectors) | |
| # HYBRID requires a sparse embedder configured separately | |
| _vector_store = QdrantVectorStore( | |
| client=client, | |
| collection_name=settings.collection_name, | |
| embedding=embeddings, | |
| retrieval_mode=RetrievalMode.DENSE, | |
| vector_name=settings.vector_name, | |
| ) | |
| return _vector_store | |