januarevan commited on
Commit
34a8460
1 Parent(s): 362cbdc
Files changed (1) hide show
  1. main.py +6 -2
main.py CHANGED
@@ -2,8 +2,10 @@ from fastapi import FastAPI, Form, Depends, Request, File, UploadFile
2
  from fastapi.encoders import jsonable_encoder
3
  from fastapi.responses import JSONResponse
4
  from fastapi.middleware.cors import CORSMiddleware
 
5
  import os
6
  import pypdf
 
7
 
8
  from langchain.text_splitter import RecursiveCharacterTextSplitter
9
  from pymilvus import MilvusClient, db, utility, Collection, CollectionSchema, FieldSchema, DataType
@@ -45,9 +47,10 @@ def split_documents(document_data):
45
  def create_a_collection(milvus_client, collection_name):
46
  content = FieldSchema(name="content", dtype=DataType.VARCHAR, max_length=4096)
47
  vector = FieldSchema(name="vector", dtype=DataType.FLOAT_VECTOR, dim=1024)
 
48
 
49
  schema = CollectionSchema([
50
- content, vector
51
  ])
52
 
53
  vector_index = {
@@ -84,6 +87,7 @@ async def insert(file: UploadFile = File(...)):
84
  data_objects = []
85
  for doc in splitted_document_data:
86
  data = {
 
87
  "vector": document_to_embeddings(doc.page_content),
88
  "content": doc.page_content,
89
  }
@@ -100,7 +104,7 @@ async def insert(file: UploadFile = File(...)):
100
  return JSONResponse(status_code=200, content={"result": 'good'})
101
 
102
  @app.post("/rag")
103
- async def insert(question):
104
  if not question:
105
  return JSONResponse(status_code=400, content={"message": "Please a question!"})
106
 
 
2
  from fastapi.encoders import jsonable_encoder
3
  from fastapi.responses import JSONResponse
4
  from fastapi.middleware.cors import CORSMiddleware
5
+
6
  import os
7
  import pypdf
8
+ from uuid import uuid4
9
 
10
  from langchain.text_splitter import RecursiveCharacterTextSplitter
11
  from pymilvus import MilvusClient, db, utility, Collection, CollectionSchema, FieldSchema, DataType
 
47
  def create_a_collection(milvus_client, collection_name):
48
  content = FieldSchema(name="content", dtype=DataType.VARCHAR, max_length=4096)
49
  vector = FieldSchema(name="vector", dtype=DataType.FLOAT_VECTOR, dim=1024)
50
+ id = FieldSchema(name="id", dtype=DataType.VARCHAR, max_length=40, is_primary=True)
51
 
52
  schema = CollectionSchema([
53
+ id, content, vector
54
  ])
55
 
56
  vector_index = {
 
87
  data_objects = []
88
  for doc in splitted_document_data:
89
  data = {
90
+ "id": str(uuid4()),
91
  "vector": document_to_embeddings(doc.page_content),
92
  "content": doc.page_content,
93
  }
 
104
  return JSONResponse(status_code=200, content={"result": 'good'})
105
 
106
  @app.post("/rag")
107
+ async def rag(question):
108
  if not question:
109
  return JSONResponse(status_code=400, content={"message": "Please a question!"})
110