Content
# RAG API
This project is an API server based on FastAPI that implements a document-based question-answering system.
## Features
1. Document Upload and Vector Store Storage
- Supports PDF and CSV files
- Automatic document splitting and embedding
- Stored in Chroma vector store
2. Document Search
- Natural language query-based search
- Similarity-based document search
## Installation
1. Install the required packages:
```bash
pip install -r requirements.txt
```
2. Set environment variables:
```bash
export OPENAI_API_KEY="your-api-key"
```
## Running the Application
```bash
python main.py
```
The server will run at http://localhost:8000.
## API Endpoints
1. Document Upload
- POST /upload
- Upload files in multipart/form-data format
- Supported formats: PDF, CSV
- Parameters:
- `files`: List of files to upload (required)
- `vector_store_dir`: Directory path to save the vector store (optional, default: "vector_store")
2. Document Search
- POST /query
- Pass parameters in form-data format
- Parameters:
- `query`: Search query (required)
- `vector_store_dir`: Directory path of the vector store (optional, default: "vector_store")
- `k`: Number of documents to search for (optional, default: 2)
## API Documentation
The automatically generated documentation of FastAPI can be accessed at the following URLs:
- http://localhost:8000/docs
- http://localhost:8000/redoc
## Transferring Vector Store
To reuse files stored in the vector store in another project, follow these steps:
1. Copy the desired vector store directory to the same path in the other project.
2. The following packages must also be installed in the other project:
- langchain-chroma
- langchain-openai
- Other necessary dependency packages
3. The same embedding model (OpenAIEmbeddings) must be used.
4. Required environment variables (e.g., OpenAI API key) must be correctly set.
When transferring the vector store to another project, simply copying the directory is sufficient. This will preserve the embeddings and metadata of the documents, allowing them to be used in the new project as well.
## Using Multiple Vector Stores
This project is designed to support the simultaneous use of multiple vector stores. Each vector store is stored in a different directory, and you can specify the desired vector store through the `vector_store_dir` parameter in API calls.
For example, you can create and manage separate vector stores for different projects or document sets:
```
project1_docs -> vector_store_project1
project2_docs -> vector_store_project2
research_papers -> vector_store_research
```
This allows you to manage and search each document set independently.
Connection Info
You Might Also Like
markitdown
Python tool for converting files and office documents to Markdown.
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
Filesystem
Node.js MCP Server for filesystem operations with dynamic access control.
Sequential Thinking
A structured MCP server for dynamic problem-solving and reflective thinking.
Fetch
Retrieve and process content from web pages by converting HTML into markdown format.
TrendRadar
TrendRadar: Your hotspot assistant for real news in just 30 seconds.