Mikeplockhart commited on
Commit
e055325
1 Parent(s): b82fdab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -2,13 +2,15 @@ import gradio as gr
2
  import chromadb
3
  from sentence_transformers import CrossEncoder, SentenceTransformer
4
  import json
 
5
 
6
  print("Setup client")
7
- chroma_client = chromadb.Client()
8
- collection = chroma_client.create_collection(
9
- name="food_collection",
10
- metadata={"hnsw:space": "cosine"} # l2 is the default
11
- )
 
12
 
13
  print("load data")
14
  with open("test_json.json", "r") as f:
@@ -36,12 +38,12 @@ print('upserting')
36
  print("printing item:")
37
  embedding = embedding_function([item['doc'] for item in payload])
38
  print(type(embedding))
39
- collection.add(
40
  collection_name="food",
41
  documents=[item['doc'] for item in payload],
42
  #embeddings=embedding,
43
- metadatas=[{'payload':item} for item in payload],
44
- ids=[f"id_{idx}" for idx, _ in enumerate(payload)]
45
  )
46
 
47
  def search_chroma(query:str):
 
2
  import chromadb
3
  from sentence_transformers import CrossEncoder, SentenceTransformer
4
  import json
5
+ from qdrant_client import QdrantClient
6
 
7
  print("Setup client")
8
+ #chroma_client = chromadb.Client()
9
+ #collection = chroma_client.create_collection(
10
+ #name="food_collection",
11
+ #metadata={"hnsw:space": "cosine"} # l2 is the default
12
+ #)
13
+ client = QdrantClient(":memory:")
14
 
15
  print("load data")
16
  with open("test_json.json", "r") as f:
 
38
  print("printing item:")
39
  embedding = embedding_function([item['doc'] for item in payload])
40
  print(type(embedding))
41
+ client.add(
42
  collection_name="food",
43
  documents=[item['doc'] for item in payload],
44
  #embeddings=embedding,
45
+ metadata=[{'payload':item} for item in payload],
46
+ ids=[idx for idx, _ in enumerate(payload)]
47
  )
48
 
49
  def search_chroma(query:str):