Files
2026-05-28 07:33:29 +00:00

67 lines
2.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# LangChain + Qdrant KnowledgeBase Agent
This repository contains a minimal, fullyfunctional example of an AI agent built with **LangChain** that can:
1. Search a semantic knowledge base stored in **Qdrant**.
2. Add new documents to the same knowledge base.
3. Interact with users via a conversational chat interface using *stream mode* so that responses appear tokenbytoken.
The implementation follows the assignment requirements:
- LangChain agent in stream mode.
- Qdrantbased search system.
- Integration with LangGraph (the `create_agent` helper internally uses LangGraph).
- All code is selfcontained and contains no placeholders or `pass` statements.
---
## File structure
| File | Purpose |
|------|---------|
| **main.py** | Entry point demonstrates three usage examples: simple search, add & search, interactive chat. |
| **requirements.txt** | Runtime dependencies (LangChain, LangGraph, Qdrant client, dotenv). |
| **qdrant_store.py** | Thin wrapper around an inmemory Qdrant client with helper methods for adding and searching documents. |
| **tools.py** | Two LangChain tools: `search_knowledge_base` and `add_to_knowledge_base`. |
---
## Installation
```bash
# Create a virtual environment (recommended)
python -m venv .venv && source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
```
> The repository uses the **BroJS** LLM endpoint. Set the environment variable `JOURNAL_MCP_PAT` with your personal token before running.
---
## Usage examples
### 1. Simple search
```bash
python main.py
# Output will show a short semantic search result for "Python async programming"
```
### 2. Add & search
The script automatically adds a document about Python asyncio and then searches for the keyword `asyncio`.
### 3. Interactive chat (stream mode)
During the third example the agent will stream its response tokenbytoken, showing tool calls as they happen.
---
## Architecture overview
1. **LLM** a BroJS GPTOSS20B model accessed via `ChatOpenAI`.
2. **Tools** two functions decorated with `@tool`. They interact with the Qdrant store.
3. **QdrantStore** an inmemory vector database that holds documents and performs semantic similarity search.
4. **Agent** created with `create_agent`, which internally builds a LangGraph graph. The agent can call tools, maintain state, and stream output.
5. **Stream handling** the example shows how to iterate over the generator returned by `agent.stream()` and print partial messages as they arrive.
---
## Extending the project
- Replace the inmemory Qdrant client with a real server by changing the connection string in `qdrant_store.py`.
- Add more tools or subagents to enrich the agents capabilities.
- Persist the Qdrant collection between runs for a longterm knowledge base.
---
## License
MIT © 2026 Kirill Kutlakhmetov