Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from fastapi import FastAPI
- import chromadb
- from chromadb.config import Settings
- app = FastAPI()
- # Initialize Chroma client
- client = chromadb.Client(Settings(
- chroma_db_impl="duckdb+parquet",
- persist_directory="/path/to/persist"
- ))
- collection = client.get_or_create_collection(name="documents")
- @app.post("/add_document")
- async def add_document(content: str, metadata: dict):
- collection.add(
- documents=[content],
- metadatas=[metadata],
- ids=[str(hash(content))]
- )
- return {"status": "success"}
- @app.get("/search")
- async def search(query: str):
- results = collection.query(
- query_texts=[query],
- n_results=5
- )
- return results
- # Run with: uvicorn app:app --reload
Advertisement
Add Comment
Please, Sign In to add comment