File size: 1,151 Bytes
2cc8ae2
fad2247
 
c32bf6e
2cc8ae2
0e01434
2cc8ae2
 
 
 
 
fad2247
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2cc8ae2
fad2247
 
 
 
 
 
 
 
 
 
 
 
db1ad09
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from langchain.embeddings import OpenAIEmbeddings, HuggingFaceEmbeddings, HuggingFaceInferenceAPIEmbeddings
from langchain.vectorstores import Chroma, Qdrant
from qdrant_client import QdrantClient
from qdrant_client.models import Distance, VectorParams
from dotenv import load_dotenv
import os

provider_retrieval_model = "HF"
embeddingmodel = "BAAI/bge-small-en-v1.5"
load_dotenv()
HF_Token = os.environ.get("HF_TOKEN")
client_path = f"./vectorstore"
collection_name = f"collection"
provider_retrieval_model = "HF"

def create_vectorstore(docs):
    
    if provider_retrieval_model == "HF":
      qdrantClient = QdrantClient(path=client_path, prefer_grpc=True)
    
      embeddings = HuggingFaceInferenceAPIEmbeddings(
          api_key=HF_Token, model_name=embeddingmodel
      )
    
      dim = 1024
    

    
    qdrantClient.create_collection(
        collection_name=collection_name,
        vectors_config=VectorParams(size=dim, distance=Distance.COSINE),
    )
    
    vectorstore = Qdrant(
        client=qdrantClient,
        collection_name=collection_name,
        embeddings=embeddings,
    )
    
    vectorstore.add_documents(docs)