feat: solution for 'Повторный экзамен #2: Сравнительный обзор 3 сущностей (Tavily)'
This commit is contained in:
@@ -1,58 +1,76 @@
|
||||
# Tavily Compare
|
||||
# Vector Search Comparison Project
|
||||
|
||||
A lightweight Node.js library that compares three entities by querying the [Tavily](https://tavily.com) API.
|
||||
The library uses a single, unified async/await approach for all HTTP requests and provides clear error handling.
|
||||
This repository demonstrates a simple integration with **Qdrant** and provides a markdown table comparing three popular search and vector store services: **Tavily**, **Qdrant**, and **Pinecone**.
|
||||
|
||||
## Installation
|
||||
## Features
|
||||
|
||||
```bash
|
||||
npm install tavily-compare
|
||||
```
|
||||
- **Qdrant Integration**
|
||||
A lightweight wrapper (`src/qdrantIntegration.js`) that allows you to:
|
||||
- Create and delete collections
|
||||
- Upsert points (vectors + payload)
|
||||
- Perform similarity search
|
||||
|
||||
## Usage
|
||||
- **Markdown Comparison**
|
||||
The `comparison.md` file contains a side‑by‑side table highlighting key differences and use cases for each service.
|
||||
|
||||
```js
|
||||
import { compare } from 'tavily-compare';
|
||||
## Getting Started
|
||||
|
||||
// Set your Tavily API key in the environment
|
||||
process.env.TAVILY_API_KEY = 'YOUR_TAVILY_API_KEY';
|
||||
1. **Clone the repository**
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const results = await compare('entity1', 'entity2', 'entity3');
|
||||
console.log(results);
|
||||
// {
|
||||
// entity1: { ...tavily response... },
|
||||
// entity2: { ...tavily response... },
|
||||
// entity3: { ...tavily response... }
|
||||
// }
|
||||
} catch (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
})();
|
||||
```
|
||||
```bash
|
||||
git clone https://git.brojs.ru/kuzakhmetovartur/povtornyy-ekzamen-2-sravnitelnyy-obzor-3.git
|
||||
cd povtornyy-ekzamen-2-sravnitelnyy-obzor-3
|
||||
```
|
||||
|
||||
## API
|
||||
2. **Install dependencies**
|
||||
|
||||
### `compare(entity1, entity2, entity3)`
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
|
||||
- **Parameters**
|
||||
- `entity1` – *string* – First entity to compare.
|
||||
- `entity2` – *string* – Second entity to compare.
|
||||
- `entity3` – *string* – Third entity to compare.
|
||||
- **Returns** – *Promise\<Object\>* – An object mapping each entity to its Tavily API response.
|
||||
- **Throws** – *Error* – If any API call fails or if arguments are missing.
|
||||
3. **Set up environment variables**
|
||||
|
||||
## Testing
|
||||
Create a `.env` file or export the following variables in your shell:
|
||||
|
||||
Run the test suite with:
|
||||
```bash
|
||||
export QDRANT_URL="https://your-qdrant-instance.com"
|
||||
export QDRANT_API_KEY="your_api_key" # optional if your instance is public
|
||||
```
|
||||
|
||||
```bash
|
||||
npm test
|
||||
```
|
||||
4. **Use the Qdrant client**
|
||||
|
||||
The tests mock the Tavily API to ensure no real HTTP requests are made.
|
||||
```js
|
||||
const QdrantClient = require('./src/qdrantIntegration');
|
||||
|
||||
const client = new QdrantClient({
|
||||
url: process.env.QDRANT_URL,
|
||||
apiKey: process.env.QDRANT_API_KEY,
|
||||
});
|
||||
|
||||
async function demo() {
|
||||
await client.createCollection('demo', { size: 1536, distance: 'Cosine' });
|
||||
await client.upsertPoints('demo', [
|
||||
{ id: 1, vector: Array(1536).fill(0.1), payload: { title: 'Example' } },
|
||||
]);
|
||||
const results = await client.searchPoints('demo', Array(1536).fill(0.1));
|
||||
console.log(results);
|
||||
}
|
||||
|
||||
demo().catch(console.error);
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
- **Qdrant Integration** – `src/qdrantIntegration.js`
|
||||
Contains the `QdrantClient` class with methods for CRUD operations and search.
|
||||
|
||||
- **Comparison Table** – `comparison.md`
|
||||
Provides a concise comparison of Tavily, Qdrant, and Pinecone.
|
||||
|
||||
## License
|
||||
|
||||
MIT © Your Name
|
||||
MIT © Your Name
|
||||
|
||||
---
|
||||
|
||||
Feel free to extend the client or add more detailed tests. Happy coding!
|
||||
Reference in New Issue
Block a user