|
|
1 gün önce | |
|---|---|---|
| arquivos | 2 gün önce | |
| .dockerignore | 2 gün önce | |
| .tool-versions | 2 gün önce | |
| Dockerfile | 2 gün önce | |
| README.md | 1 gün önce | |
| api.ts | 2 gün önce | |
| bun.lock | 2 gün önce | |
| busca.ts | 2 gün önce | |
| database.ts | 2 gün önce | |
| embeddings.sqlite | 1 gün önce | |
| index.ts | 2 gün önce | |
| insert-embeddings.ts | 2 gün önce | |
| package.json | 2 gün önce | |
| tsconfig.json | 2 gün önce | |
| types.ts | 2 gün önce | |
| utils.ts | 2 gün önce |
A Retrieval-Augmented Generation (RAG) system designed for academic document search and retrieval. This system uses vector embeddings to enable semantic search across academic content, providing relevant context for AI-powered question answering.
The system consists of several key components:
insert-embeddings.ts): Reads Markdown files, chunks content, generates embeddings using Ollama, and stores in SQLitedatabase.ts): SQLite-based storage for documents and their vector embeddingsbusca.ts): Performs semantic search using cosine similarityapi.ts): RESTful API for querying the systemutils.ts): Helper functions for similarity calculationsnomic-embed-text:latest)Clone the repository
git clone <repository-url>
cd base-de-dados-academia
Install dependencies
bun install
Start Ollama and pull the embedding model
ollama serve
ollama pull nomic-embed-text:latest
Start the REST API server:
bun run api.ts
The server will start on port 3000 (configurable via PORT environment variable).
.md) files in the arquivos/novos/ directoryRun the document ingestion script:
bun run insert-embeddings.ts
This will:
.md files in arquivos/novos/arquivos/processados/arquivos/erro/Run the example search script:
bun run index.ts
This demonstrates searching for similar documents to a sample query.
Search for documents similar to a given prompt.
Request Body:
{
"prompt": "What is the suffix of a markdown file?",
"topK": 3,
"limiarSimilaridade": 0.5
}
Parameters:
prompt (required): The search query texttopK (optional): Number of top results to return (default: 3)limiarSimilaridade (optional): Minimum similarity threshold (default: 0.5)Response:
{
"contexto": "Documentos relevantes:\n\n--- Documento 1: file.md (similaridade: 0.85) ---\nContent...",
"resultados": [
{
"documento": {
"nome": "file.md",
"caminho": "/path/to/file.md",
"conteudo": "Content...",
"tamanho": 1234,
"embedding": [0.1, 0.2, ...]
},
"similaridade": 0.85
}
]
}
Example using curl:
curl -X POST http://localhost:3000/api/embeddings \
-H "Content-Type: application/json" \
-d '{"prompt": "on docker?", "topK": 3, "limiarSimilaridade": 0.5}'
The system can be configured using environment variables:
PORT: API server port (default: 3000)DB_PATH: Path to SQLite database file (default: ./embeddings.sqlite)OLLAMA_BASE_URL: Ollama API endpoint (default: http://localhost:11434)docker build --pull -t rag-academia-server .
docker run \
--restart=always \
-v $(pwd)/embeddings.sqlite:/tmp/embeddings.sqlite \
--name rag-academia-server \
-e OLLAMA_BASE_URL=http://host.docker.internal:11434 \
-e DB_PATH=/tmp/embeddings.sqlite \
-e PORT=3000 \
--network=host \
-d \
rag-academia-server
Notes:
host.docker.internal to access Ollama running on the hostOLLAMA_BASE_URL if Ollama is running in a separate containerDocument Ingestion:
arquivos/novos/Query Processing:
Similarity Calculation:
cos(θ) = (A · B) / (||A|| × ||B||)├── api.ts # REST API server
├── busca.ts # Search and similarity functions
├── database.ts # SQLite vector database operations
├── index.ts # Example usage script
├── insert-embeddings.ts # Document ingestion pipeline
├── types.ts # TypeScript type definitions
├── utils.ts # Utility functions
├── arquivos/ # Document storage
│ ├── novos/ # New documents to process
│ ├── processados/ # Successfully processed documents
│ └── erro/ # Failed processing documents
├── prompts/ # Prompt templates
├── Dockerfile # Container configuration
├── package.json # Dependencies and scripts
└── tsconfig.json # TypeScript configuration
This project is licensed under the MIT License - see the LICENSE file for details.